Chilkat Online Tools

unicodeC / easybill REST API / Update position group

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *v_number;
    const wchar_t *name;
    const wchar_t *description;
    const wchar_t *login_id;
    const wchar_t *display_name;
    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.

    // {
    //   "number": "<string>",
    //   "name": "<string>",
    //   "description": null,
    //   "login_id": "<long>",
    //   "display_name": "<string>",
    //   "id": "<long>"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"number",L"<string>");
    CkJsonObjectW_UpdateString(json,L"name",L"<string>");
    CkJsonObjectW_UpdateNull(json,L"description");
    CkJsonObjectW_UpdateString(json,L"login_id",L"<long>");
    CkJsonObjectW_UpdateString(json,L"display_name",L"<string>");
    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");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://api.easybill.de/rest/v1/position-groups/:id",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // {
    //   "number": "<string>",
    //   "name": "<string>",
    //   "description": null,
    //   "login_id": "<long>",
    //   "display_name": "<string>",
    //   "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.

    v_number = CkJsonObjectW_stringOf(jResp,L"number");
    name = CkJsonObjectW_stringOf(jResp,L"name");
    description = CkJsonObjectW_stringOf(jResp,L"description");
    login_id = CkJsonObjectW_stringOf(jResp,L"login_id");
    display_name = CkJsonObjectW_stringOf(jResp,L"display_name");
    id = CkJsonObjectW_stringOf(jResp,L"id");


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

    }

Curl Command

curl -X PUT
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "number": "<string>",
  "name": "<string>",
  "description": null,
  "login_id": "<long>",
  "display_name": "<string>",
  "id": "<long>"
}'
https://api.easybill.de/rest/v1/position-groups/:id

Postman Collection Item JSON

{
  "name": "Update position group",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"number\": \"<string>\",\n  \"name\": \"<string>\",\n  \"description\": null,\n  \"login_id\": \"<long>\",\n  \"display_name\": \"<string>\",\n  \"id\": \"<long>\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/position-groups/:id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "position-groups",
        ":id"
      ],
      "variable": [
        {
          "key": "id",
          "value": "<long>",
          "description": "(Required) ID of position goup"
        }
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "originalRequest": {
        "method": "PUT",
        "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  \"number\": \"<string>\",\n  \"name\": \"<string>\",\n  \"description\": null,\n  \"login_id\": \"<long>\",\n  \"display_name\": \"<string>\",\n  \"id\": \"<long>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/position-groups/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "position-groups",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"number\": \"<string>\",\n  \"name\": \"<string>\",\n  \"description\": null,\n  \"login_id\": \"<long>\",\n  \"display_name\": \"<string>\",\n  \"id\": \"<long>\"\n}"
    },
    {
      "name": "Invalid position group",
      "originalRequest": {
        "method": "PUT",
        "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  \"number\": \"<string>\",\n  \"name\": \"<string>\",\n  \"description\": null,\n  \"login_id\": \"<long>\",\n  \"display_name\": \"<string>\",\n  \"id\": \"<long>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/position-groups/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "position-groups",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Too Many Requests",
      "originalRequest": {
        "method": "PUT",
        "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  \"number\": \"<string>\",\n  \"name\": \"<string>\",\n  \"description\": null,\n  \"login_id\": \"<long>\",\n  \"display_name\": \"<string>\",\n  \"id\": \"<long>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/position-groups/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "position-groups",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}