Chilkat Online Tools

C# / easybill REST API / Create position

Back to Collection Items

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

Chilkat.Http http = new Chilkat.Http();
bool success;

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

Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("number","<string>");
json.UpdateString("description","<string>");
json.UpdateString("sale_price","<float>");
json.UpdateString("id","<long>");
json.UpdateString("type","PRODUCT");
json.UpdateString("document_note","<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.UpdateString("login_id","<long>");
json.UpdateString("price_type","NETTO");
json.UpdateInt("vat_percent",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.UpdateString("cost_price","<float>");
json.UpdateNull("export_cost1");
json.UpdateNull("export_cost2");
json.UpdateString("group_id","<long>");
json.UpdateString("stock","NO");
json.UpdateInt("stock_count",0);
json.UpdateBool("stock_limit_notify",false);
json.UpdateString("stock_limit_notify_frequency","ALWAYS");
json.UpdateInt("stock_limit",0);
json.UpdateNull("quantity");
json.UpdateBool("archived",false);

http.SetRequestHeader("Content-Type","application/json");
http.SetRequestHeader("Authorization","{{apiKey}}");
http.SetRequestHeader("Accept","application/json");

Chilkat.HttpResponse resp = http.PostJson3("https://api.easybill.de/rest/v1/positions","application/json",json);
if (http.LastMethodSuccess == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());

int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(resp.Header);
    Debug.WriteLine("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

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