Chilkat Online Tools

C / Zoho CRM REST APIs / Revoking Tokens

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkHttpRequest req;
    HCkJsonObject jsonFormData1;
    HCkHttpResponse resp;

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

    http = CkHttp_Create();

    req = CkHttpRequest_Create();
    CkHttpRequest_putHttpVerb(req,"POST");
    CkHttpRequest_putPath(req,"/oauth/v2/token/revoke");
    CkHttpRequest_putContentType(req,"multipart/form-data");

    jsonFormData1 = CkJsonObject_Create();
    CkHttpRequest_AddStringForUpload2(req,"token","",jsonFormData1,"utf-8","application/json");

    resp = CkHttp_SynchronousRequest(http,"domain.com",443,TRUE,req);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkJsonObject_Dispose(jsonFormData1);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkHttpRequest_Dispose(req);
    CkJsonObject_Dispose(jsonFormData1);

    }

Curl Command

curl -X POST
	--form 'token={{refresh-token}}'
https://domain.com/oauth/v2/token/revoke

Postman Collection Item JSON

{
  "name": "Revoking Tokens",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "if (responseCode.code === 200)",
          "{",
          "    var jsonData = JSON.parse(responseBody);",
          "    ",
          "    if (jsonData.status == \"sucess\")",
          "    {",
          "        pm.environment.set(\"refresh-token\", \"\");",
          "        pm.environment.set(\"access-token\", \"\");",
          "        pm.environment.set(\"expiry-time\", \"\");",
          "    }",
          "}"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "token",
          "value": "{{refresh-token}}",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{accounts-domain}}/oauth/v2/token/revoke",
      "host": [
        "{{accounts-domain}}"
      ],
      "path": [
        "oauth",
        "v2",
        "token",
        "revoke"
      ]
    },
    "description": "### Step 5: Revoking Tokens\n\nIn case if you wish to revoke the refresh_token, use the below approach."
  },
  "response": [
  ]
}