Chilkat Online Tools

ERROR!

------------------- GenerateCode ----------------------
ImpliedContentType: application/x-www-form-urlencoded
explicitContentType: application/x-www-form-urlencoded
---- begin chilkat script ----
// This example assumes the Chilkat API to have been previously unlocked.
// See {{-global_unlock:::Global Unlock Sample-}} for sample code.

new Http http;
ckbool success;

new HttpRequest req;

new JsonObject jsonParam1;
call req.AddParam("username",jsonParam1.Emit());

new JsonObject jsonParam2;
call req.AddParam("password",jsonParam2.Emit());
call req.AddParam("grant_type","password");

new JsonObject jsonParam4;
call req.AddParam("client_id",jsonParam4.Emit());

new JsonObject jsonParam5;
call req.AddParam("client_secret",jsonParam5.Emit());
call req.AddParam("scope","lp");


new HttpResponse resp;
req.HttpVerb = "POST";
req.ContentType = "application/x-www-form-urlencoded";
success = http.PostUrlEncoded("https://domain.com/", req,resp);
if (success == ckfalse) {
println http.LastErrorText;
return;
}

println resp.StatusCode;
println resp.BodyStr;

---- end chilkat script ----

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

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

set req [new_CkHttpRequest]

set jsonParam1 [new_CkJsonObject]

CkHttpRequest_AddParam $req "username" [CkJsonObject_emit $jsonParam1]

set jsonParam2 [new_CkJsonObject]

CkHttpRequest_AddParam $req "password" [CkJsonObject_emit $jsonParam2]
CkHttpRequest_AddParam $req "grant_type" "password"

set jsonParam4 [new_CkJsonObject]

CkHttpRequest_AddParam $req "client_id" [CkJsonObject_emit $jsonParam4]

set jsonParam5 [new_CkJsonObject]

CkHttpRequest_AddParam $req "client_secret" [CkJsonObject_emit $jsonParam5]
CkHttpRequest_AddParam $req "scope" "lp"

set resp [new_CkHttpResponse]

CkHttpRequest_put_HttpVerb $req "POST"
CkHttpRequest_put_ContentType $req "application/x-www-form-urlencoded"
ERROR: Assignment type mismatch.  ExpressionType=HttpResponse, atgType=ckbool

if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkHttpRequest $req
    delete_CkJsonObject $jsonParam1
    delete_CkJsonObject $jsonParam2
    delete_CkJsonObject $jsonParam4
    delete_CkJsonObject $jsonParam5
    delete_CkHttpResponse $resp
    exit
}

puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]

delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkJsonObject $jsonParam1
delete_CkJsonObject $jsonParam2
delete_CkJsonObject $jsonParam4
delete_CkJsonObject $jsonParam5
delete_CkHttpResponse $resp

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": [
  ]
}