Chilkat Online Tools

Swift3 / easybill REST API / Create 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

    // 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>",
    //   "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
    // }

    let json = CkoJsonObject()!
    json.update("number", value: "<string>")
    json.update("description", value: "<string>")
    json.update("sale_price", value: "<float>")
    json.update("id", value: "<long>")
    json.update("type", value: "PRODUCT")
    json.update("document_note", value: "<string>")
    json.updateNull("note")
    json.updateNull("unit")
    json.updateNull("export_identifier")
    json.updateNull("export_identifier_extended.NULL")
    json.updateNull("export_identifier_extended.nStb")
    json.updateNull("export_identifier_extended.nStbUstID")
    json.updateNull("export_identifier_extended.nStbNoneUstID")
    json.updateNull("export_identifier_extended.nStbIm")
    json.updateNull("export_identifier_extended.revc")
    json.updateNull("export_identifier_extended.IG")
    json.updateNull("export_identifier_extended.AL")
    json.updateNull("export_identifier_extended.sStfr")
    json.updateNull("export_identifier_extended.smallBusiness")
    json.update("login_id", value: "<long>")
    json.update("price_type", value: "NETTO")
    json.updateInt("vat_percent", value: 19)
    json.updateNull("sale_price2")
    json.updateNull("sale_price3")
    json.updateNull("sale_price4")
    json.updateNull("sale_price5")
    json.updateNull("sale_price6")
    json.updateNull("sale_price7")
    json.updateNull("sale_price8")
    json.updateNull("sale_price9")
    json.updateNull("sale_price10")
    json.update("cost_price", value: "<float>")
    json.updateNull("export_cost1")
    json.updateNull("export_cost2")
    json.update("group_id", value: "<long>")
    json.update("stock", value: "NO")
    json.updateInt("stock_count", value: 0)
    json.updateBool("stock_limit_notify", value: false)
    json.update("stock_limit_notify_frequency", value: "ALWAYS")
    json.updateInt("stock_limit", value: 0)
    json.updateNull("quantity")
    json.updateBool("archived", value: false)

    http.setRequestHeader("Content-Type", value: "application/json")
    http.setRequestHeader("Authorization", value: "{{apiKey}}")
    http.setRequestHeader("Accept", value: "application/json")

    var resp: CkoHttpResponse? = http.postJson3("https://api.easybill.de/rest/v1/positions", contentType: "application/json", json: json)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp!.getBodySb(sbResponseBody)

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp!.statusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp!.header!)")
        print("Failed.")
        resp = nil
        return
    }

    resp = nil

    // 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.string(of: "number")
    var description: String? = jResp.string(of: "description")
    var sale_price: String? = jResp.string(of: "sale_price")
    var id: String? = jResp.string(of: "id")
    var v_type: String? = jResp.string(of: "type")
    var document_note: String? = jResp.string(of: "document_note")
    var note: String? = jResp.string(of: "note")
    var unit: String? = jResp.string(of: "unit")
    var export_identifier: String? = jResp.string(of: "export_identifier")
    var v_NULL: String? = jResp.string(of: "export_identifier_extended.NULL")
    var NStb: String? = jResp.string(of: "export_identifier_extended.nStb")
    var NStbUstID: String? = jResp.string(of: "export_identifier_extended.nStbUstID")
    var NStbNoneUstID: String? = jResp.string(of: "export_identifier_extended.nStbNoneUstID")
    var NStbIm: String? = jResp.string(of: "export_identifier_extended.nStbIm")
    var Revc: String? = jResp.string(of: "export_identifier_extended.revc")
    var IG: String? = jResp.string(of: "export_identifier_extended.IG")
    var AL: String? = jResp.string(of: "export_identifier_extended.AL")
    var SStfr: String? = jResp.string(of: "export_identifier_extended.sStfr")
    var SmallBusiness: String? = jResp.string(of: "export_identifier_extended.smallBusiness")
    var login_id: String? = jResp.string(of: "login_id")
    var price_type: String? = jResp.string(of: "price_type")
    var vat_percent: Int = jResp.int(of: "vat_percent").intValue
    var sale_price2: String? = jResp.string(of: "sale_price2")
    var sale_price3: String? = jResp.string(of: "sale_price3")
    var sale_price4: String? = jResp.string(of: "sale_price4")
    var sale_price5: String? = jResp.string(of: "sale_price5")
    var sale_price6: String? = jResp.string(of: "sale_price6")
    var sale_price7: String? = jResp.string(of: "sale_price7")
    var sale_price8: String? = jResp.string(of: "sale_price8")
    var sale_price9: String? = jResp.string(of: "sale_price9")
    var sale_price10: String? = jResp.string(of: "sale_price10")
    var cost_price: String? = jResp.string(of: "cost_price")
    var export_cost1: String? = jResp.string(of: "export_cost1")
    var export_cost2: String? = jResp.string(of: "export_cost2")
    var group_id: String? = jResp.string(of: "group_id")
    var stock: String? = jResp.string(of: "stock")
    var stock_count: Int = jResp.int(of: "stock_count").intValue
    var stock_limit_notify: Bool = jResp.bool(of: "stock_limit_notify")
    var stock_limit_notify_frequency: String? = jResp.string(of: "stock_limit_notify_frequency")
    var stock_limit: Int = jResp.int(of: "stock_limit").intValue
    var quantity: String? = jResp.string(of: "quantity")
    var archived: Bool = jResp.bool(of: "archived")

}

Curl Command

curl -X POST
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "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
}'
https://api.easybill.de/rest/v1/positions

Postman Collection Item JSON

{
  "name": "Create position",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\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}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/positions",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "positions"
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "originalRequest": {
        "method": "POST",
        "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  \"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}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/positions",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_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": "Too Many Requests",
      "originalRequest": {
        "method": "POST",
        "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  \"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}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/positions",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "positions"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}