Chilkat Online Tools

Swift3 / DocuSign Admin API / 03 Refresh Access Token

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    let req = CkoHttpRequest()!

    let jsonParam1 = CkoJsonObject()!
    req.addParam("refresh_token", value: jsonParam1.emit())
    req.addParam("grant_type", value: "refresh_token")

    req.addHeader("Authorization", value: "Basic {{encodedKeys}}")

    var resp: CkoHttpResponse? = http.postUrlEncoded("https://{{hostenv}}/oauth/token", req: req)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

Curl Command

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

Postman Collection Item JSON

{
  "name": "03 Refresh 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": "refresh_token",
          "value": "{{refreshToken}}"
        },
        {
          "key": "grant_type",
          "value": "refresh_token"
        }
      ]
    },
    "url": {
      "raw": "https://{{hostenv}}/oauth/token",
      "protocol": "https",
      "host": [
        "{{hostenv}}"
      ],
      "path": [
        "oauth",
        "token"
      ]
    }
  },
  "response": [
  ]
}