Chilkat Online Tools

PureBasic / easybill REST API / Fetch positions 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>")
    CkJsonObject::ckUpdateString(queryParams,"type","PRODUCT")
    CkJsonObject::ckUpdateString(queryParams,"number","<string>")

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

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://api.easybill.de/rest/v1/positions",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": [
    ;     {
    ;       "number": "<string>",
    ;       "description": "<string>",
    ;       "sale_price": "<float>",
    ;       "id": "<long>",
    ;       "type": "PRODUCT",
    ;       "document_note": "<string>",
    ;       "note": null,
    ;       "unit": null,
    ;       "export_identifier": null,
    ;       "export_identifier_extended": {
    ;         "NULL": null,
    ;         "nStb": null,
    ;         "nStbUstID": null,
    ;         "nStbNoneUstID": null,
    ;         "nStbIm": null,
    ;         "revc": null,
    ;         "IG": null,
    ;         "AL": null,
    ;         "sStfr": null,
    ;         "smallBusiness": null
    ;       },
    ;       "login_id": "<long>",
    ;       "price_type": "NETTO",
    ;       "vat_percent": 19,
    ;       "sale_price2": null,
    ;       "sale_price3": null,
    ;       "sale_price4": null,
    ;       "sale_price5": null,
    ;       "sale_price6": null,
    ;       "sale_price7": null,
    ;       "sale_price8": null,
    ;       "sale_price9": null,
    ;       "sale_price10": null,
    ;       "cost_price": "<float>",
    ;       "export_cost1": null,
    ;       "export_cost2": null,
    ;       "group_id": "<long>",
    ;       "stock": "NO",
    ;       "stock_count": 0,
    ;       "stock_limit_notify": false,
    ;       "stock_limit_notify_frequency": "ALWAYS",
    ;       "stock_limit": 0,
    ;       "quantity": null,
    ;       "archived": false
    ;     },
    ;     {
    ;       "number": "<string>",
    ;       "description": "<string>",
    ;       "sale_price": "<float>",
    ;       "id": "<long>",
    ;       "type": "PRODUCT",
    ;       "document_note": "<string>",
    ;       "note": null,
    ;       "unit": null,
    ;       "export_identifier": null,
    ;       "export_identifier_extended": {
    ;         "NULL": null,
    ;         "nStb": null,
    ;         "nStbUstID": null,
    ;         "nStbNoneUstID": null,
    ;         "nStbIm": null,
    ;         "revc": null,
    ;         "IG": null,
    ;         "AL": null,
    ;         "sStfr": null,
    ;         "smallBusiness": null
    ;       },
    ;       "login_id": "<long>",
    ;       "price_type": "NETTO",
    ;       "vat_percent": 19,
    ;       "sale_price2": null,
    ;       "sale_price3": null,
    ;       "sale_price4": null,
    ;       "sale_price5": null,
    ;       "sale_price6": null,
    ;       "sale_price7": null,
    ;       "sale_price8": null,
    ;       "sale_price9": null,
    ;       "sale_price10": null,
    ;       "cost_price": "<float>",
    ;       "export_cost1": null,
    ;       "export_cost2": null,
    ;       "group_id": "<long>",
    ;       "stock": "NO",
    ;       "stock_count": 0,
    ;       "stock_limit_notify": false,
    ;       "stock_limit_notify_frequency": "ALWAYS",
    ;       "stock_limit": 0,
    ;       "quantity": null,
    ;       "archived": false
    ;     }
    ;   ]
    ; }

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

    v_number.s
    description.s
    sale_price.s
    id.s
    v_type.s
    document_note.s
    note.s
    unit.s
    export_identifier.s
    v_NULL.s
    NStb.s
    NStbUstID.s
    NStbNoneUstID.s
    NStbIm.s
    Revc.s
    IG.s
    AL.s
    SStfr.s
    SmallBusiness.s
    login_id.s
    price_type.s
    vat_percent.i
    sale_price2.s
    sale_price3.s
    sale_price4.s
    sale_price5.s
    sale_price6.s
    sale_price7.s
    sale_price8.s
    sale_price9.s
    sale_price10.s
    cost_price.s
    export_cost1.s
    export_cost2.s
    group_id.s
    stock.s
    stock_count.i
    stock_limit_notify.i
    stock_limit_notify_frequency.s
    stock_limit.i
    quantity.s
    archived.i

    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)
        v_number = CkJsonObject::ckStringOf(jResp,"items[i].number")
        description = CkJsonObject::ckStringOf(jResp,"items[i].description")
        sale_price = CkJsonObject::ckStringOf(jResp,"items[i].sale_price")
        id = CkJsonObject::ckStringOf(jResp,"items[i].id")
        v_type = CkJsonObject::ckStringOf(jResp,"items[i].type")
        document_note = CkJsonObject::ckStringOf(jResp,"items[i].document_note")
        note = CkJsonObject::ckStringOf(jResp,"items[i].note")
        unit = CkJsonObject::ckStringOf(jResp,"items[i].unit")
        export_identifier = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier")
        v_NULL = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.NULL")
        NStb = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.nStb")
        NStbUstID = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.nStbUstID")
        NStbNoneUstID = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.nStbNoneUstID")
        NStbIm = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.nStbIm")
        Revc = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.revc")
        IG = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.IG")
        AL = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.AL")
        SStfr = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.sStfr")
        SmallBusiness = CkJsonObject::ckStringOf(jResp,"items[i].export_identifier_extended.smallBusiness")
        login_id = CkJsonObject::ckStringOf(jResp,"items[i].login_id")
        price_type = CkJsonObject::ckStringOf(jResp,"items[i].price_type")
        vat_percent = CkJsonObject::ckIntOf(jResp,"items[i].vat_percent")
        sale_price2 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price2")
        sale_price3 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price3")
        sale_price4 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price4")
        sale_price5 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price5")
        sale_price6 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price6")
        sale_price7 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price7")
        sale_price8 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price8")
        sale_price9 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price9")
        sale_price10 = CkJsonObject::ckStringOf(jResp,"items[i].sale_price10")
        cost_price = CkJsonObject::ckStringOf(jResp,"items[i].cost_price")
        export_cost1 = CkJsonObject::ckStringOf(jResp,"items[i].export_cost1")
        export_cost2 = CkJsonObject::ckStringOf(jResp,"items[i].export_cost2")
        group_id = CkJsonObject::ckStringOf(jResp,"items[i].group_id")
        stock = CkJsonObject::ckStringOf(jResp,"items[i].stock")
        stock_count = CkJsonObject::ckIntOf(jResp,"items[i].stock_count")
        stock_limit_notify = CkJsonObject::ckBoolOf(jResp,"items[i].stock_limit_notify")
        stock_limit_notify_frequency = CkJsonObject::ckStringOf(jResp,"items[i].stock_limit_notify_frequency")
        stock_limit = CkJsonObject::ckIntOf(jResp,"items[i].stock_limit")
        quantity = CkJsonObject::ckStringOf(jResp,"items[i].quantity")
        archived = CkJsonObject::ckBoolOf(jResp,"items[i].archived")
        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"
	-d "type=PRODUCT"
	-d "number=%3Cstring%3E"
	-H "Authorization: {{apiKey}}"
	-H "Accept: application/json"
https://api.easybill.de/rest/v1/positions

Postman Collection Item JSON

{
  "name": "Fetch positions list",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/positions?limit=<integer>&page=<integer>&type=PRODUCT&number=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "positions"
      ],
      "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."
        },
        {
          "key": "type",
          "value": "PRODUCT",
          "description": "Filter positions by type."
        },
        {
          "key": "number",
          "value": "<string>",
          "description": "Filter positions by number. You can add multiple numbers separate by comma like no,no,no."
        }
      ]
    }
  },
  "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}}/positions?limit=<integer>&page=<integer>&type=PRODUCT&number=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions"
          ],
          "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."
            },
            {
              "key": "type",
              "value": "PRODUCT",
              "description": "Filter positions by type."
            },
            {
              "key": "number",
              "value": "<string>",
              "description": "Filter positions by number. You can add multiple numbers separate by comma like no,no,no."
            }
          ]
        }
      },
      "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      \"number\": \"<string>\",\n      \"description\": \"<string>\",\n      \"sale_price\": \"<float>\",\n      \"id\": \"<long>\",\n      \"type\": \"PRODUCT\",\n      \"document_note\": \"<string>\",\n      \"note\": null,\n      \"unit\": null,\n      \"export_identifier\": null,\n      \"export_identifier_extended\": {\n        \"NULL\": null,\n        \"nStb\": null,\n        \"nStbUstID\": null,\n        \"nStbNoneUstID\": null,\n        \"nStbIm\": null,\n        \"revc\": null,\n        \"IG\": null,\n        \"AL\": null,\n        \"sStfr\": null,\n        \"smallBusiness\": null\n      },\n      \"login_id\": \"<long>\",\n      \"price_type\": \"NETTO\",\n      \"vat_percent\": 19,\n      \"sale_price2\": null,\n      \"sale_price3\": null,\n      \"sale_price4\": null,\n      \"sale_price5\": null,\n      \"sale_price6\": null,\n      \"sale_price7\": null,\n      \"sale_price8\": null,\n      \"sale_price9\": null,\n      \"sale_price10\": null,\n      \"cost_price\": \"<float>\",\n      \"export_cost1\": null,\n      \"export_cost2\": null,\n      \"group_id\": \"<long>\",\n      \"stock\": \"NO\",\n      \"stock_count\": 0,\n      \"stock_limit_notify\": false,\n      \"stock_limit_notify_frequency\": \"ALWAYS\",\n      \"stock_limit\": 0,\n      \"quantity\": null,\n      \"archived\": false\n    },\n    {\n      \"number\": \"<string>\",\n      \"description\": \"<string>\",\n      \"sale_price\": \"<float>\",\n      \"id\": \"<long>\",\n      \"type\": \"PRODUCT\",\n      \"document_note\": \"<string>\",\n      \"note\": null,\n      \"unit\": null,\n      \"export_identifier\": null,\n      \"export_identifier_extended\": {\n        \"NULL\": null,\n        \"nStb\": null,\n        \"nStbUstID\": null,\n        \"nStbNoneUstID\": null,\n        \"nStbIm\": null,\n        \"revc\": null,\n        \"IG\": null,\n        \"AL\": null,\n        \"sStfr\": null,\n        \"smallBusiness\": null\n      },\n      \"login_id\": \"<long>\",\n      \"price_type\": \"NETTO\",\n      \"vat_percent\": 19,\n      \"sale_price2\": null,\n      \"sale_price3\": null,\n      \"sale_price4\": null,\n      \"sale_price5\": null,\n      \"sale_price6\": null,\n      \"sale_price7\": null,\n      \"sale_price8\": null,\n      \"sale_price9\": null,\n      \"sale_price10\": null,\n      \"cost_price\": \"<float>\",\n      \"export_cost1\": null,\n      \"export_cost2\": null,\n      \"group_id\": \"<long>\",\n      \"stock\": \"NO\",\n      \"stock_count\": 0,\n      \"stock_limit_notify\": false,\n      \"stock_limit_notify_frequency\": \"ALWAYS\",\n      \"stock_limit\": 0,\n      \"quantity\": null,\n      \"archived\": false\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}}/positions?limit=<integer>&page=<integer>&type=PRODUCT&number=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions"
          ],
          "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."
            },
            {
              "key": "type",
              "value": "PRODUCT",
              "description": "Filter positions by type."
            },
            {
              "key": "number",
              "value": "<string>",
              "description": "Filter positions by number. You can add multiple numbers separate by comma like no,no,no."
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}