Chilkat Online Tools

autoit / easybill REST API / Create a stock entry for a position

Back to Collection Items

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

$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess

; Use this online tool to generate code from sample JSON: Generate Code to Create JSON

; The following JSON is sent in the request body.

; {
;   "stock_count": "<long>",
;   "position_id": "<long>",
;   "id": "<long>",
;   "note": "<string>",
;   "document_id": "<long>",
;   "document_position_id": "<long>",
;   "stored_at": "<string>",
;   "created_at": "<string>",
;   "updated_at": "<string>"
; }

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("stock_count","<long>")
$oJson.UpdateString("position_id","<long>")
$oJson.UpdateString("id","<long>")
$oJson.UpdateString("note","<string>")
$oJson.UpdateString("document_id","<long>")
$oJson.UpdateString("document_position_id","<long>")
$oJson.UpdateString("stored_at","<string>")
$oJson.UpdateString("created_at","<string>")
$oJson.UpdateString("updated_at","<string>")

$oHttp.SetRequestHeader "Content-Type","application/json"
$oHttp.SetRequestHeader "Authorization","{{apiKey}}"
$oHttp.SetRequestHeader "Accept","application/json"

Local $oResp = $oHttp.PostJson3("https://api.easybill.de/rest/v1/stocks","application/json",$oJson)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)

$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)

    Exit
EndIf

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

; {
;   "stock_count": "<long>",
;   "position_id": "<long>",
;   "id": "<long>",
;   "note": "<string>",
;   "document_id": "<long>",
;   "document_position_id": "<long>",
;   "stored_at": "<string>",
;   "created_at": "<string>",
;   "updated_at": "<string>"
; }

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

Local $stock_count = $oJResp.StringOf("stock_count")
Local $sPosition_id = $oJResp.StringOf("position_id")
Local $sId = $oJResp.StringOf("id")
Local $sNote = $oJResp.StringOf("note")
Local $sDocument_id = $oJResp.StringOf("document_id")
Local $sDocument_position_id = $oJResp.StringOf("document_position_id")
Local $stored_at = $oJResp.StringOf("stored_at")
Local $sCreated_at = $oJResp.StringOf("created_at")
Local $sUpdated_at = $oJResp.StringOf("updated_at")

Curl Command

curl -X POST
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "stock_count": "<long>",
  "position_id": "<long>",
  "id": "<long>",
  "note": "<string>",
  "document_id": "<long>",
  "document_position_id": "<long>",
  "stored_at": "<string>",
  "created_at": "<string>",
  "updated_at": "<string>"
}'
https://api.easybill.de/rest/v1/stocks

Postman Collection Item JSON

{
  "name": "Create a stock entry for a position",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"stock_count\": \"<long>\",\n  \"position_id\": \"<long>\",\n  \"id\": \"<long>\",\n  \"note\": \"<string>\",\n  \"document_id\": \"<long>\",\n  \"document_position_id\": \"<long>\",\n  \"stored_at\": \"<string>\",\n  \"created_at\": \"<string>\",\n  \"updated_at\": \"<string>\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/stocks",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "stocks"
      ]
    }
  },
  "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  \"stock_count\": \"<long>\",\n  \"position_id\": \"<long>\",\n  \"id\": \"<long>\",\n  \"note\": \"<string>\",\n  \"document_id\": \"<long>\",\n  \"document_position_id\": \"<long>\",\n  \"stored_at\": \"<string>\",\n  \"created_at\": \"<string>\",\n  \"updated_at\": \"<string>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/stocks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "stocks"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"stock_count\": \"<long>\",\n  \"position_id\": \"<long>\",\n  \"id\": \"<long>\",\n  \"note\": \"<string>\",\n  \"document_id\": \"<long>\",\n  \"document_position_id\": \"<long>\",\n  \"stored_at\": \"<string>\",\n  \"created_at\": \"<string>\",\n  \"updated_at\": \"<string>\"\n}"
    },
    {
      "name": "Invalid position_id or stock_count",
      "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  \"stock_count\": \"<long>\",\n  \"position_id\": \"<long>\",\n  \"id\": \"<long>\",\n  \"note\": \"<string>\",\n  \"document_id\": \"<long>\",\n  \"document_position_id\": \"<long>\",\n  \"stored_at\": \"<string>\",\n  \"created_at\": \"<string>\",\n  \"updated_at\": \"<string>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/stocks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "stocks"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "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  \"stock_count\": \"<long>\",\n  \"position_id\": \"<long>\",\n  \"id\": \"<long>\",\n  \"note\": \"<string>\",\n  \"document_id\": \"<long>\",\n  \"document_position_id\": \"<long>\",\n  \"stored_at\": \"<string>\",\n  \"created_at\": \"<string>\",\n  \"updated_at\": \"<string>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/stocks",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "stocks"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}