Chilkat Online Tools

PureBasic / easybill REST API / Fetch tasks list

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"limit","<integer>")
    CkJsonObject::ckUpdateString(queryParams,"page","<integer>")

    CkHttp::ckSetRequestHeader(http,"Authorization","{{apiKey}}")
    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://api.easybill.de/rest/v1/tasks",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

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

    ; {
    ;   "page": "<integer>",
    ;   "pages": "<integer>",
    ;   "limit": "<integer>",
    ;   "total": "<integer>",
    ;   "items": [
    ;     {
    ;       "name": "<string>",
    ;       "status": "CANCEL",
    ;       "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
    ;     },
    ;     {
    ;       "name": "<string>",
    ;       "status": "CANCEL",
    ;       "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

    name.s
    status.s
    category.s
    category_custom.s
    created_at.s
    customer_id.s
    description.s
    document_id.s
    end_at.s
    finish_at.s
    id.s
    login_id.s
    position_id.s
    priority.s
    project_id.s
    start_at.s
    status_percent.s

    page.s = CkJsonObject::ckStringOf(jResp,"page")
    pages.s = CkJsonObject::ckStringOf(jResp,"pages")
    limit.s = CkJsonObject::ckStringOf(jResp,"limit")
    total.s = CkJsonObject::ckStringOf(jResp,"total")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"items")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        name = CkJsonObject::ckStringOf(jResp,"items[i].name")
        status = CkJsonObject::ckStringOf(jResp,"items[i].status")
        category = CkJsonObject::ckStringOf(jResp,"items[i].category")
        category_custom = CkJsonObject::ckStringOf(jResp,"items[i].category_custom")
        created_at = CkJsonObject::ckStringOf(jResp,"items[i].created_at")
        customer_id = CkJsonObject::ckStringOf(jResp,"items[i].customer_id")
        description = CkJsonObject::ckStringOf(jResp,"items[i].description")
        document_id = CkJsonObject::ckStringOf(jResp,"items[i].document_id")
        end_at = CkJsonObject::ckStringOf(jResp,"items[i].end_at")
        finish_at = CkJsonObject::ckStringOf(jResp,"items[i].finish_at")
        id = CkJsonObject::ckStringOf(jResp,"items[i].id")
        login_id = CkJsonObject::ckStringOf(jResp,"items[i].login_id")
        position_id = CkJsonObject::ckStringOf(jResp,"items[i].position_id")
        priority = CkJsonObject::ckStringOf(jResp,"items[i].priority")
        project_id = CkJsonObject::ckStringOf(jResp,"items[i].project_id")
        start_at = CkJsonObject::ckStringOf(jResp,"items[i].start_at")
        status_percent = CkJsonObject::ckStringOf(jResp,"items[i].status_percent")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

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

Postman Collection Item JSON

{
  "name": "Fetch tasks list",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/tasks?limit=<integer>&page=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "tasks"
      ],
      "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."
        }
      ]
    }
  },
  "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}}/tasks?limit=<integer>&page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "tasks"
          ],
          "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."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"page\": \"<integer>\",\n  \"pages\": \"<integer>\",\n  \"limit\": \"<integer>\",\n  \"total\": \"<integer>\",\n  \"items\": [\n    {\n      \"name\": \"<string>\",\n      \"status\": \"CANCEL\",\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    },\n    {\n      \"name\": \"<string>\",\n      \"status\": \"CANCEL\",\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    }\n  ]\n}"
    },
    {
      "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}}/tasks?limit=<integer>&page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "tasks"
          ],
          "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."
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}