Chilkat Online Tools

C / EPC 2.0 - Partner Sandbox - 19.4 November [External] / [Lender] Create Lender Authentication Token

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkHttpRequest req;
    HCkJsonObject jsonParam1;
    HCkJsonObject jsonParam2;
    HCkJsonObject jsonParam4;
    HCkJsonObject jsonParam5;
    HCkHttpResponse resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_Create();

    req = CkHttpRequest_Create();

    jsonParam1 = CkJsonObject_Create();
    CkHttpRequest_AddParam(req,"username",CkJsonObject_emit(jsonParam1));

    jsonParam2 = CkJsonObject_Create();
    CkHttpRequest_AddParam(req,"password",CkJsonObject_emit(jsonParam2));
    CkHttpRequest_AddParam(req,"grant_type","password");

    jsonParam4 = CkJsonObject_Create();
    CkHttpRequest_AddParam(req,"client_id",CkJsonObject_emit(jsonParam4));

    jsonParam5 = CkJsonObject_Create();
    CkHttpRequest_AddParam(req,"client_secret",CkJsonObject_emit(jsonParam5));
    CkHttpRequest_AddParam(req,"scope","lp");

    resp = CkHttp_PostUrlEncoded(http,"https://domain.com/",req);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkJsonObject_Dispose(jsonParam1);
        CkJsonObject_Dispose(jsonParam2);
        CkJsonObject_Dispose(jsonParam4);
        CkJsonObject_Dispose(jsonParam5);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkHttpRequest_Dispose(req);
    CkJsonObject_Dispose(jsonParam1);
    CkJsonObject_Dispose(jsonParam2);
    CkJsonObject_Dispose(jsonParam4);
    CkJsonObject_Dispose(jsonParam5);

    }

Curl Command

curl -X POST
	-H "Content-Type: application/x-www-form-urlencoded"
	--data-urlencode 'username={{encompass_username}}@encompass:{{encompass_instance_id}}'
	--data-urlencode 'password={{encompass_password}}'
	--data-urlencode 'grant_type=password'
	--data-urlencode 'client_id={{lender_client_id}}'
	--data-urlencode 'client_secret={{lender_client_secret}}'
	--data-urlencode 'scope=lp'
https://domain.com/

Postman Collection Item JSON

{
  "name": "[Lender] Create Lender Authentication Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Extract Lender oAuth token from response body",
          "var jsonData = JSON.parse(responseBody);",
          "var lenderToken = jsonData.access_token;",
          "",
          "// Set to an environment variable",
          "postman.setEnvironmentVariable(\"lender_token\", lenderToken);"
        ]
      }
    }
  ],
  "_postman_id": "dcaf78e5-430f-47e0-9d98-ef4313352ace",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/x-www-form-urlencoded",
        "type": "text"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "username",
          "value": "{{encompass_username}}@encompass:{{encompass_instance_id}}",
          "type": "text"
        },
        {
          "key": "password",
          "value": "{{encompass_password}}",
          "type": "text"
        },
        {
          "key": "grant_type",
          "value": "password",
          "type": "text"
        },
        {
          "key": "client_id",
          "value": "{{lender_client_id}}",
          "type": "text"
        },
        {
          "key": "client_secret",
          "value": "{{lender_client_secret}}",
          "type": "text"
        },
        {
          "key": "scope",
          "value": "lp",
          "type": "text"
        }
      ]
    },
    "url": "{{api_host}}/oauth2/v1/token"
  },
  "response": [
  ]
}