Chilkat Online Tools

ERROR!

------------------- GenerateCode ----------------------
ImpliedContentType: 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("code",jsonParam1.Emit());
call req.AddParam("grant_type","authorization_code");

call req.AddHeader("Authorization","Basic {{encodedKeys}}");

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

println resp.StatusCode;
println resp.BodyStr;

---- end chilkat script ----

Go / DocuSign REST API / 01 Authorize Code Grant Access Token

Back to Collection Items

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

    http := Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">chilkat.NewHttp()
    var success bool

    req := HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">chilkat.NewHttpRequest()

    jsonParam1 := JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">chilkat.NewJsonObject()
    req.AddParam("code",*jsonParam1.Emit())
    req.AddParam("grant_type","authorization_code")

    req.AddHeader("Authorization","Basic {{encodedKeys}}")

    resp := HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">chilkat.NewHttpResponse()
    req.SetHttpVerb("POST")
    req.SetContentType("application/x-www-form-urlencoded")
ERROR: Assignment type mismatch.  ExpressionType=HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse, atgType=ckbool

    if success == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        req.DisposeHttpRequest()
        jsonParam1.DisposeJsonObject()
        resp.DisposeHttpResponse()
        return
    }

    fmt.Println(resp.StatusCode())
    fmt.Println(resp.BodyStr())

    http.DisposeHttp()
    req.DisposeHttpRequest()
    jsonParam1.DisposeJsonObject()
    resp.DisposeHttpResponse()

Curl Command

curl -X POST
	-H "Authorization: Basic {{encodedKeys}}"
	--data-urlencode 'code={{codeFromUrl}}'
	--data-urlencode 'grant_type=authorization_code'
https://{{hostenv}}/oauth/token

Postman Collection Item JSON

{
  "name": "01 Authorize Code Grant Access Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"accessToken\", jsonData.access_token);",
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"refreshToken\", jsonData.refresh_token);"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Basic {{encodedKeys}}"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "code",
          "value": "{{codeFromUrl}}"
        },
        {
          "key": "grant_type",
          "value": "authorization_code"
        }
      ]
    },
    "url": {
      "raw": "https://{{hostenv}}/oauth/token",
      "protocol": "https",
      "host": [
        "{{hostenv}}"
      ],
      "path": [
        "oauth",
        "token"
      ]
    }
  },
  "response": [
  ]
}