Chilkat Online Tools

C / PandaDoc API Reference / List Templates

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    int count;
    const char *v_next;
    const char *previous;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    CkHttp_SetRequestHeader(http,"Authorization","API-Key {{api_key}}");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://api.pandadoc.com/public/v1/templates",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttp_getLastStatus(http);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttp_lastHeader(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "count": 0,
    //   "next": null,
    //   "previous": null,
    //   "results": [
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    count = CkJsonObject_IntOf(jResp,"count");
    v_next = CkJsonObject_stringOf(jResp,"next");
    previous = CkJsonObject_stringOf(jResp,"previous");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"results");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Authorization: Bearer {{access_token}}"
	-H "Authorization: API-Key {{api_key}}"
https://api.pandadoc.com/public/v1/templates

Postman Collection Item JSON

{
  "name": "List Templates",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{access_token}}",
        "disabled": true
      },
      {
        "key": "Authorization",
        "value": "API-Key {{api_key}}",
        "type": "text"
      }
    ],
    "url": {
      "raw": "https://api.pandadoc.com/public/v1/templates",
      "protocol": "https",
      "host": [
        "api",
        "pandadoc",
        "com"
      ],
      "path": [
        "public",
        "v1",
        "templates"
      ]
    },
    "description": "For details go to [https://developers.pandadoc.com/v1/reference#list-templates](https://developers.pandadoc.com/v1/reference#list-templates)."
  },
  "response": [
    {
      "name": "Empty Response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json;charset=UTF-8",
            "description": "The mime type of this content"
          }
        ],
        "url": {
          "raw": "https://api.pandadoc.com/public/v1/templates",
          "protocol": "https",
          "host": [
            "api",
            "pandadoc",
            "com"
          ],
          "path": [
            "public",
            "v1",
            "templates"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "javascript",
      "header": [
        {
          "key": "Allow",
          "value": "GET, DELETE, HEAD, OPTIONS",
          "name": "Allow",
          "description": "Valid actions for a specified resource. To be used for a 405 Method not allowed"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache",
          "name": "Cache-Control",
          "description": "Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds"
        },
        {
          "key": "Connection",
          "value": "keep-alive",
          "name": "Connection",
          "description": "Options that are desired for the connection"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip",
          "name": "Content-Encoding",
          "description": "The type of encoding used on the data."
        },
        {
          "key": "Content-Type",
          "value": "application/json",
          "name": "Content-Type",
          "description": "The mime type of this content"
        },
        {
          "key": "Date",
          "value": "Mon, 22 Aug 2016 17:01:13 GMT",
          "name": "Date",
          "description": "The date and time that the message was sent"
        },
        {
          "key": "Expires",
          "value": "Mon, 22 Aug 2016 17:01:12 GMT",
          "name": "Expires",
          "description": "Gives the date/time after which the response is considered stale"
        },
        {
          "key": "Pragma",
          "value": "no-cache",
          "name": "Pragma",
          "description": "Implementation-specific headers that may have various effects anywhere along the request-response chain."
        },
        {
          "key": "Server",
          "value": "nginx/1.4.6 (Ubuntu)",
          "name": "Server",
          "description": "A name for the server"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked",
          "name": "Transfer-Encoding",
          "description": "The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity."
        }
      ],
      "cookie": [
      ],
      "body": "{\"count\": 0, \"next\": null, \"previous\": null, \"results\": []}"
    }
  ]
}