Chilkat Online Tools

unicodeC / easybill REST API / Create task

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 *name;
    const wchar_t *status;
    const wchar_t *category;
    const wchar_t *category_custom;
    const wchar_t *created_at;
    const wchar_t *customer_id;
    const wchar_t *description;
    const wchar_t *document_id;
    const wchar_t *end_at;
    const wchar_t *finish_at;
    const wchar_t *id;
    const wchar_t *login_id;
    const wchar_t *position_id;
    const wchar_t *priority;
    const wchar_t *project_id;
    const wchar_t *start_at;
    const wchar_t *status_percent;

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

    // {
    //   "name": "<string>",
    //   "status": "PROCESSING",
    //   "category": null,
    //   "category_custom": null,
    //   "created_at": "<dateTime>",
    //   "customer_id": null,
    //   "description": null,
    //   "document_id": null,
    //   "end_at": "<dateTime>",
    //   "finish_at": "<dateTime>",
    //   "id": "<long>",
    //   "login_id": "<long>",
    //   "position_id": null,
    //   "priority": "NORMAL",
    //   "project_id": null,
    //   "start_at": null,
    //   "status_percent": null
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"name",L"<string>");
    CkJsonObjectW_UpdateString(json,L"status",L"PROCESSING");
    CkJsonObjectW_UpdateNull(json,L"category");
    CkJsonObjectW_UpdateNull(json,L"category_custom");
    CkJsonObjectW_UpdateString(json,L"created_at",L"<dateTime>");
    CkJsonObjectW_UpdateNull(json,L"customer_id");
    CkJsonObjectW_UpdateNull(json,L"description");
    CkJsonObjectW_UpdateNull(json,L"document_id");
    CkJsonObjectW_UpdateString(json,L"end_at",L"<dateTime>");
    CkJsonObjectW_UpdateString(json,L"finish_at",L"<dateTime>");
    CkJsonObjectW_UpdateString(json,L"id",L"<long>");
    CkJsonObjectW_UpdateString(json,L"login_id",L"<long>");
    CkJsonObjectW_UpdateNull(json,L"position_id");
    CkJsonObjectW_UpdateString(json,L"priority",L"NORMAL");
    CkJsonObjectW_UpdateNull(json,L"project_id");
    CkJsonObjectW_UpdateNull(json,L"start_at");
    CkJsonObjectW_UpdateNull(json,L"status_percent");

    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/tasks",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)

    // {
    //   "name": "<string>",
    //   "status": "PROCESSING",
    //   "category": null,
    //   "category_custom": null,
    //   "created_at": "<dateTime>",
    //   "customer_id": null,
    //   "description": null,
    //   "document_id": null,
    //   "end_at": "<dateTime>",
    //   "finish_at": "<dateTime>",
    //   "id": "<long>",
    //   "login_id": "<long>",
    //   "position_id": null,
    //   "priority": "NORMAL",
    //   "project_id": null,
    //   "start_at": null,
    //   "status_percent": null
    // }

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

    name = CkJsonObjectW_stringOf(jResp,L"name");
    status = CkJsonObjectW_stringOf(jResp,L"status");
    category = CkJsonObjectW_stringOf(jResp,L"category");
    category_custom = CkJsonObjectW_stringOf(jResp,L"category_custom");
    created_at = CkJsonObjectW_stringOf(jResp,L"created_at");
    customer_id = CkJsonObjectW_stringOf(jResp,L"customer_id");
    description = CkJsonObjectW_stringOf(jResp,L"description");
    document_id = CkJsonObjectW_stringOf(jResp,L"document_id");
    end_at = CkJsonObjectW_stringOf(jResp,L"end_at");
    finish_at = CkJsonObjectW_stringOf(jResp,L"finish_at");
    id = CkJsonObjectW_stringOf(jResp,L"id");
    login_id = CkJsonObjectW_stringOf(jResp,L"login_id");
    position_id = CkJsonObjectW_stringOf(jResp,L"position_id");
    priority = CkJsonObjectW_stringOf(jResp,L"priority");
    project_id = CkJsonObjectW_stringOf(jResp,L"project_id");
    start_at = CkJsonObjectW_stringOf(jResp,L"start_at");
    status_percent = CkJsonObjectW_stringOf(jResp,L"status_percent");


    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 '{
  "name": "<string>",
  "status": "PROCESSING",
  "category": null,
  "category_custom": null,
  "created_at": "<dateTime>",
  "customer_id": null,
  "description": null,
  "document_id": null,
  "end_at": "<dateTime>",
  "finish_at": "<dateTime>",
  "id": "<long>",
  "login_id": "<long>",
  "position_id": null,
  "priority": "NORMAL",
  "project_id": null,
  "start_at": null,
  "status_percent": null
}'
https://api.easybill.de/rest/v1/tasks

Postman Collection Item JSON

{
  "name": "Create task",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"name\": \"<string>\",\n  \"status\": \"PROCESSING\",\n  \"category\": null,\n  \"category_custom\": null,\n  \"created_at\": \"<dateTime>\",\n  \"customer_id\": null,\n  \"description\": null,\n  \"document_id\": null,\n  \"end_at\": \"<dateTime>\",\n  \"finish_at\": \"<dateTime>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"position_id\": null,\n  \"priority\": \"NORMAL\",\n  \"project_id\": null,\n  \"start_at\": null,\n  \"status_percent\": null\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/tasks",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "tasks"
      ]
    }
  },
  "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  \"name\": \"<string>\",\n  \"status\": \"PROCESSING\",\n  \"category\": null,\n  \"category_custom\": null,\n  \"created_at\": \"<dateTime>\",\n  \"customer_id\": null,\n  \"description\": null,\n  \"document_id\": null,\n  \"end_at\": \"<dateTime>\",\n  \"finish_at\": \"<dateTime>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"position_id\": null,\n  \"priority\": \"NORMAL\",\n  \"project_id\": null,\n  \"start_at\": null,\n  \"status_percent\": null\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/tasks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "tasks"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"name\": \"<string>\",\n  \"status\": \"PROCESSING\",\n  \"category\": null,\n  \"category_custom\": null,\n  \"created_at\": \"<dateTime>\",\n  \"customer_id\": null,\n  \"description\": null,\n  \"document_id\": null,\n  \"end_at\": \"<dateTime>\",\n  \"finish_at\": \"<dateTime>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"position_id\": null,\n  \"priority\": \"NORMAL\",\n  \"project_id\": null,\n  \"start_at\": null,\n  \"status_percent\": null\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  \"name\": \"<string>\",\n  \"status\": \"PROCESSING\",\n  \"category\": null,\n  \"category_custom\": null,\n  \"created_at\": \"<dateTime>\",\n  \"customer_id\": null,\n  \"description\": null,\n  \"document_id\": null,\n  \"end_at\": \"<dateTime>\",\n  \"finish_at\": \"<dateTime>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"position_id\": null,\n  \"priority\": \"NORMAL\",\n  \"project_id\": null,\n  \"start_at\": null,\n  \"status_percent\": null\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/tasks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "tasks"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}