Chilkat Online Tools

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

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
req: HCkHttpRequest;
jsonParam1: HCkJsonObject;
jsonParam2: HCkJsonObject;
jsonParam4: HCkJsonObject;
jsonParam5: HCkJsonObject;
resp: HCkHttpResponse;

begin
// 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) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(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": [
  ]
}