Chilkat Online Tools

unicodeC / easybill REST API / Create text template

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *title;
    const wchar_t *text;
    const wchar_t *can_modify;
    const wchar_t *id;

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

    http = CkHttpW_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "title": "<string>",
    //   "text": "<string>",
    //   "can_modify": "<boolean>",
    //   "id": "<long>"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"title",L"<string>");
    CkJsonObjectW_UpdateString(json,L"text",L"<string>");
    CkJsonObjectW_UpdateString(json,L"can_modify",L"<boolean>");
    CkJsonObjectW_UpdateString(json,L"id",L"<long>");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"Authorization",L"{{apiKey}}");
    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_PostJson3(http,L"https://api.easybill.de/rest/v1/text-templates",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // {
    //   "title": "<string>",
    //   "text": "<string>",
    //   "can_modify": "<boolean>",
    //   "id": "<long>"
    // }

    // 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.

    title = CkJsonObjectW_stringOf(jResp,L"title");
    text = CkJsonObjectW_stringOf(jResp,L"text");
    can_modify = CkJsonObjectW_stringOf(jResp,L"can_modify");
    id = CkJsonObjectW_stringOf(jResp,L"id");


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X POST
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "title": "<string>",
  "text": "<string>",
  "can_modify": "<boolean>",
  "id": "<long>"
}'
https://api.easybill.de/rest/v1/text-templates

Postman Collection Item JSON

{
  "name": "Create text template",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"title\": \"<string>\",\n  \"text\": \"<string>\",\n  \"can_modify\": \"<boolean>\",\n  \"id\": \"<long>\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/text-templates",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "text-templates"
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"title\": \"<string>\",\n  \"text\": \"<string>\",\n  \"can_modify\": \"<boolean>\",\n  \"id\": \"<long>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/text-templates",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "text-templates"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"title\": \"<string>\",\n  \"text\": \"<string>\",\n  \"can_modify\": \"<boolean>\",\n  \"id\": \"<long>\"\n}"
    },
    {
      "name": "Too Many Requests",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"title\": \"<string>\",\n  \"text\": \"<string>\",\n  \"can_modify\": \"<boolean>\",\n  \"id\": \"<long>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/text-templates",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "text-templates"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}