Chilkat Online Tools

Swift / easybill REST API / Fetch position

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()
    var success: Bool

    http.SetRequestHeader("Authorization", value: "{{apiKey}}")
    http.SetRequestHeader("Accept", value: "application/json")

    let sbResponseBody = CkoStringBuilder()
    success = http.QuickGetSb("https://api.easybill.de/rest/v1/positions/:id", sbContent: sbResponseBody)
    if success == false {
        print("\(http.LastErrorText)")
        return
    }

    let jResp = CkoJsonObject()
    jResp.LoadSb(sbResponseBody)
    jResp.EmitCompact = false

    print("Response Body:")
    print("\(jResp.Emit())")

    var respStatusCode: Int = http.LastStatus.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(http.LastHeader)")
        print("Failed.")
        return
    }

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

    // {
    //   "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

    var v_number: String? = jResp.StringOf("number")
    var description: String? = jResp.StringOf("description")
    var sale_price: String? = jResp.StringOf("sale_price")
    var id: String? = jResp.StringOf("id")
    var v_type: String? = jResp.StringOf("type")
    var document_note: String? = jResp.StringOf("document_note")
    var note: String? = jResp.StringOf("note")
    var unit: String? = jResp.StringOf("unit")
    var export_identifier: String? = jResp.StringOf("export_identifier")
    var v_NULL: String? = jResp.StringOf("export_identifier_extended.NULL")
    var NStb: String? = jResp.StringOf("export_identifier_extended.nStb")
    var NStbUstID: String? = jResp.StringOf("export_identifier_extended.nStbUstID")
    var NStbNoneUstID: String? = jResp.StringOf("export_identifier_extended.nStbNoneUstID")
    var NStbIm: String? = jResp.StringOf("export_identifier_extended.nStbIm")
    var Revc: String? = jResp.StringOf("export_identifier_extended.revc")
    var IG: String? = jResp.StringOf("export_identifier_extended.IG")
    var AL: String? = jResp.StringOf("export_identifier_extended.AL")
    var SStfr: String? = jResp.StringOf("export_identifier_extended.sStfr")
    var SmallBusiness: String? = jResp.StringOf("export_identifier_extended.smallBusiness")
    var login_id: String? = jResp.StringOf("login_id")
    var price_type: String? = jResp.StringOf("price_type")
    var vat_percent: Int = jResp.IntOf("vat_percent").intValue
    var sale_price2: String? = jResp.StringOf("sale_price2")
    var sale_price3: String? = jResp.StringOf("sale_price3")
    var sale_price4: String? = jResp.StringOf("sale_price4")
    var sale_price5: String? = jResp.StringOf("sale_price5")
    var sale_price6: String? = jResp.StringOf("sale_price6")
    var sale_price7: String? = jResp.StringOf("sale_price7")
    var sale_price8: String? = jResp.StringOf("sale_price8")
    var sale_price9: String? = jResp.StringOf("sale_price9")
    var sale_price10: String? = jResp.StringOf("sale_price10")
    var cost_price: String? = jResp.StringOf("cost_price")
    var export_cost1: String? = jResp.StringOf("export_cost1")
    var export_cost2: String? = jResp.StringOf("export_cost2")
    var group_id: String? = jResp.StringOf("group_id")
    var stock: String? = jResp.StringOf("stock")
    var stock_count: Int = jResp.IntOf("stock_count").intValue
    var stock_limit_notify: Bool = jResp.BoolOf("stock_limit_notify")
    var stock_limit_notify_frequency: String? = jResp.StringOf("stock_limit_notify_frequency")
    var stock_limit: Int = jResp.IntOf("stock_limit").intValue
    var quantity: String? = jResp.StringOf("quantity")
    var archived: Bool = jResp.BoolOf("archived")

}

Curl Command

curl -X GET
	-H "Authorization: {{apiKey}}"
	-H "Accept: application/json"
https://api.easybill.de/rest/v1/positions/:id

Postman Collection Item JSON

{
  "name": "Fetch position",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/positions/:id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "positions",
        ":id"
      ],
      "variable": [
        {
          "key": "id",
          "value": "<long>",
          "description": "(Required) ID of position"
        }
      ]
    }
  },
  "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/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\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}"
    },
    {
      "name": "Not found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/positions/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions",
            ":id"
          ],
          "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}}/positions/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}