Chilkat Online Tools

Node.js / PandaDoc API Reference / Create Access Token

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

    var req = new chilkat.HttpRequest();
    req.AddParam("grant_type","authorization_code");

    var jsonParam2 = new chilkat.JsonObject();
    req.AddParam("client_id",jsonParam2.Emit());

    var jsonParam3 = new chilkat.JsonObject();
    req.AddParam("client_secret",jsonParam3.Emit());
    req.AddParam("code","");
    req.AddParam("scope","read+write");

    var jsonParam6 = new chilkat.JsonObject();
    req.AddParam("redirect_uri",jsonParam6.Emit());

    req.AddHeader("Authorization","Bearer <access_token>");

    // resp: HttpResponse
    var resp = http.PostUrlEncoded("https://api.pandadoc.com/oauth2/access_token",req);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	--data-urlencode 'grant_type=authorization_code'
	--data-urlencode 'client_id={{client_id}}'
	--data-urlencode 'client_secret={{client_secret}}'
	--data-urlencode 'code='
	--data-urlencode 'scope=read+write'
	--data-urlencode 'redirect_uri={{redirect_uri}}'
https://api.pandadoc.com/oauth2/access_token

Postman Collection Item JSON

{
  "name": "Create Access Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "if (jsonData.access_token !== undefined) {",
          "    postman.setEnvironmentVariable(\"access_token\", jsonData.access_token);",
          "}",
          "if (jsonData.refresh_token !== undefined) {",
          "    postman.setEnvironmentVariable(\"refresh_token\", jsonData.refresh_token);",
          "}"
        ]
      }
    }
  ],
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "grant_type",
          "value": "authorization_code",
          "type": "text"
        },
        {
          "key": "client_id",
          "value": "{{client_id}}",
          "type": "text"
        },
        {
          "key": "client_secret",
          "value": "{{client_secret}}",
          "type": "text"
        },
        {
          "key": "code",
          "value": "",
          "type": "text"
        },
        {
          "key": "scope",
          "value": "read+write",
          "type": "text"
        },
        {
          "key": "redirect_uri",
          "value": "{{redirect_uri}}",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "https://api.pandadoc.com/oauth2/access_token",
      "protocol": "https",
      "host": [
        "api",
        "pandadoc",
        "com"
      ],
      "path": [
        "oauth2",
        "access_token"
      ]
    },
    "description": "Provide values to variables: client_id, client_secret ([Postman environments](https://www.getpostman.com/docs/postman/environments_and_globals/manage_environments) is great for it).\n\nProvide value for one-off variable code.\n\nFor details go to [https://developers.pandadoc.com/v1/reference#create-an-access_token](https://developers.pandadoc.com/v1/reference#create-an-access_token).\n\nFor details of authentication process go to [https://developers.pandadoc.com/v1/reference#authentication-process](https://developers.pandadoc.com/v1/reference#authentication-process)."
  },
  "response": [
  ]
}