Chilkat Online Tools

delphiDll / easybill REST API / Fetch specified position-group discount by id

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
queryParams: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
customer_id: PWideChar;
position_group_id: Integer;
id: PWideChar;
discount: Integer;
discount_type: PWideChar;

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

http := CkHttp_Create();

queryParams := CkJsonObject_Create();
CkJsonObject_UpdateString(queryParams,'limit','<integer>');
CkJsonObject_UpdateString(queryParams,'page','<integer>');

CkHttp_SetRequestHeader(http,'Authorization','{{apiKey}}');
CkHttp_SetRequestHeader(http,'Accept','application/json');

resp := CkHttp_QuickRequestParams(http,'GET','https://api.easybill.de/rest/v1/discounts/position-group/:id',queryParams);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

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

// {
//   "customer_id": "<long>",
//   "position_group_id": -30250132,
//   "id": "<long>",
//   "discount": 0,
//   "discount_type": "PERCENT"
// }

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

customer_id := CkJsonObject__stringOf(jResp,'customer_id');
position_group_id := CkJsonObject_IntOf(jResp,'position_group_id');
id := CkJsonObject__stringOf(jResp,'id');
discount := CkJsonObject_IntOf(jResp,'discount');
discount_type := CkJsonObject__stringOf(jResp,'discount_type');

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

Curl Command

curl -G -d "limit=%3Cinteger%3E"
	-d "page=%3Cinteger%3E"
	-H "Authorization: {{apiKey}}"
	-H "Accept: application/json"
https://api.easybill.de/rest/v1/discounts/position-group/:id

Postman Collection Item JSON

{
  "name": "Fetch specified position-group discount by id",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/discounts/position-group/:id?limit=<integer>&page=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "discounts",
        "position-group",
        ":id"
      ],
      "query": [
        {
          "key": "limit",
          "value": "<integer>",
          "description": "Limited the result. Default is 100. Maximum can be 1000."
        },
        {
          "key": "page",
          "value": "<integer>",
          "description": "Set current Page. Default is 1."
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "<long>",
          "description": "(Required) ID of the discount"
        }
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/discounts/position-group/:id?limit=<integer>&page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "discounts",
            "position-group",
            ":id"
          ],
          "query": [
            {
              "key": "limit",
              "value": "<integer>",
              "description": "Limited the result. Default is 100. Maximum can be 1000."
            },
            {
              "key": "page",
              "value": "<integer>",
              "description": "Set current Page. Default is 1."
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"customer_id\": \"<long>\",\n  \"position_group_id\": -30250132,\n  \"id\": \"<long>\",\n  \"discount\": 0,\n  \"discount_type\": \"PERCENT\"\n}"
    },
    {
      "name": "Not found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/discounts/position-group/:id?limit=<integer>&page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "discounts",
            "position-group",
            ":id"
          ],
          "query": [
            {
              "key": "limit",
              "value": "<integer>",
              "description": "Limited the result. Default is 100. Maximum can be 1000."
            },
            {
              "key": "page",
              "value": "<integer>",
              "description": "Set current Page. Default is 1."
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Too Many Requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/discounts/position-group/:id?limit=<integer>&page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "discounts",
            "position-group",
            ":id"
          ],
          "query": [
            {
              "key": "limit",
              "value": "<integer>",
              "description": "Limited the result. Default is 100. Maximum can be 1000."
            },
            {
              "key": "page",
              "value": "<integer>",
              "description": "Set current Page. Default is 1."
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}