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 ----

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkHttpRequestW req;
    HCkJsonObjectW jsonParam1;
    HCkJsonObjectW jsonParam2;
    HCkJsonObjectW jsonParam4;
    HCkJsonObjectW jsonParam5;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    req = CkHttpRequestW_Create();

    jsonParam1 = CkJsonObjectW_Create();
    CkHttpRequestW_AddParam(req,L"username",CkJsonObjectW_emit(jsonParam1));

    jsonParam2 = CkJsonObjectW_Create();
    CkHttpRequestW_AddParam(req,L"password",CkJsonObjectW_emit(jsonParam2));
    CkHttpRequestW_AddParam(req,L"grant_type",L"password");

    jsonParam4 = CkJsonObjectW_Create();
    CkHttpRequestW_AddParam(req,L"client_id",CkJsonObjectW_emit(jsonParam4));

    jsonParam5 = CkJsonObjectW_Create();
    CkHttpRequestW_AddParam(req,L"client_secret",CkJsonObjectW_emit(jsonParam5));
    CkHttpRequestW_AddParam(req,L"scope",L"lp");

    resp = CkHttpResponseW_Create();
    CkHttpRequestW_putHttpVerb(req,L"POST");
    CkHttpRequestW_putContentType(req,L"application/x-www-form-urlencoded");
ERROR: Assignment type mismatch.  ExpressionType=HttpResponse, atgType=ckbool

    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkJsonObjectW_Dispose(jsonParam1);
        CkJsonObjectW_Dispose(jsonParam2);
        CkJsonObjectW_Dispose(jsonParam4);
        CkJsonObjectW_Dispose(jsonParam5);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));


    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);
    CkJsonObjectW_Dispose(jsonParam1);
    CkJsonObjectW_Dispose(jsonParam2);
    CkJsonObjectW_Dispose(jsonParam4);
    CkJsonObjectW_Dispose(jsonParam5);
    CkHttpResponseW_Dispose(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": [
  ]
}