Chilkat Online Tools

SQL Server / easybill REST API / Fetch position

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{apiKey}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.easybill.de/rest/v1/positions/:id', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    DECLARE @v_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_number OUT, 'number'
    DECLARE @description nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'description'
    DECLARE @sale_price nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price OUT, 'sale_price'
    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @v_type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'type'
    DECLARE @document_note nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @document_note OUT, 'document_note'
    DECLARE @note nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @note OUT, 'note'
    DECLARE @unit nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @unit OUT, 'unit'
    DECLARE @export_identifier nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @export_identifier OUT, 'export_identifier'
    DECLARE @v_NULL nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_NULL OUT, 'export_identifier_extended.NULL'
    DECLARE @NStb nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NStb OUT, 'export_identifier_extended.nStb'
    DECLARE @NStbUstID nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NStbUstID OUT, 'export_identifier_extended.nStbUstID'
    DECLARE @NStbNoneUstID nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NStbNoneUstID OUT, 'export_identifier_extended.nStbNoneUstID'
    DECLARE @NStbIm nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NStbIm OUT, 'export_identifier_extended.nStbIm'
    DECLARE @Revc nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Revc OUT, 'export_identifier_extended.revc'
    DECLARE @IG nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @IG OUT, 'export_identifier_extended.IG'
    DECLARE @AL nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @AL OUT, 'export_identifier_extended.AL'
    DECLARE @SStfr nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @SStfr OUT, 'export_identifier_extended.sStfr'
    DECLARE @SmallBusiness nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @SmallBusiness OUT, 'export_identifier_extended.smallBusiness'
    DECLARE @login_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @login_id OUT, 'login_id'
    DECLARE @price_type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @price_type OUT, 'price_type'
    DECLARE @vat_percent int
    EXEC sp_OAMethod @jResp, 'IntOf', @vat_percent OUT, 'vat_percent'
    DECLARE @sale_price2 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price2 OUT, 'sale_price2'
    DECLARE @sale_price3 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price3 OUT, 'sale_price3'
    DECLARE @sale_price4 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price4 OUT, 'sale_price4'
    DECLARE @sale_price5 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price5 OUT, 'sale_price5'
    DECLARE @sale_price6 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price6 OUT, 'sale_price6'
    DECLARE @sale_price7 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price7 OUT, 'sale_price7'
    DECLARE @sale_price8 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price8 OUT, 'sale_price8'
    DECLARE @sale_price9 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price9 OUT, 'sale_price9'
    DECLARE @sale_price10 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sale_price10 OUT, 'sale_price10'
    DECLARE @cost_price nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @cost_price OUT, 'cost_price'
    DECLARE @export_cost1 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @export_cost1 OUT, 'export_cost1'
    DECLARE @export_cost2 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @export_cost2 OUT, 'export_cost2'
    DECLARE @group_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @group_id OUT, 'group_id'
    DECLARE @stock nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @stock OUT, 'stock'
    DECLARE @stock_count int
    EXEC sp_OAMethod @jResp, 'IntOf', @stock_count OUT, 'stock_count'
    DECLARE @stock_limit_notify int
    EXEC sp_OAMethod @jResp, 'BoolOf', @stock_limit_notify OUT, 'stock_limit_notify'
    DECLARE @stock_limit_notify_frequency nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @stock_limit_notify_frequency OUT, 'stock_limit_notify_frequency'
    DECLARE @stock_limit int
    EXEC sp_OAMethod @jResp, 'IntOf', @stock_limit OUT, 'stock_limit'
    DECLARE @quantity nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @quantity OUT, 'quantity'
    DECLARE @archived int
    EXEC sp_OAMethod @jResp, 'BoolOf', @archived OUT, 'archived'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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": ""
    }
  ]
}