SQL Server / easybill REST API / Download a specific file for a single version of a given document
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
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.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/pdf'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.easybill.de/rest/v1/documents/:id/versions/:versionId/items/:versionItemId/download', @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 @xmlResponse int
-- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Xml', @xmlResponse OUT
EXEC sp_OAMethod @xmlResponse, 'LoadSb', @success OUT, @sbResponseBody, 1
EXEC sp_OAMethod @xmlResponse, 'GetXml', @sTmp0 OUT
PRINT @sTmp0
-- Sample XML response:
-- (Sample code for parsing the XML response is shown below)
-- <?xml version="1.0" encoding="UTF-8"?>
-- <element>(string)</element>
-- Sample code for parsing the XML response...
-- Use this online tool to generate parsing code from sample XML: Generate XML Parsing Code
DECLARE @element nvarchar(4000)
EXEC sp_OAGetProperty @xmlResponse, 'Content', @element OUT
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @xmlResponse
END
GO
Curl Command
curl -X GET
-H "Authorization: {{apiKey}}"
-H "Accept: application/pdf"
https://api.easybill.de/rest/v1/documents/:id/versions/:versionId/items/:versionItemId/download
Postman Collection Item JSON
{
"name": "Download a specific file for a single version of a given document",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/pdf"
}
],
"url": {
"raw": "{{baseUrl}}/documents/:id/versions/:versionId/items/:versionItemId/download",
"host": [
"{{baseUrl}}"
],
"path": [
"documents",
":id",
"versions",
":versionId",
"items",
":versionItemId",
"download"
],
"variable": [
{
"key": "id",
"value": "<long>",
"description": "(Required) ID of document"
},
{
"key": "versionId",
"value": "<long>",
"description": "(Required) ID of document version"
},
{
"key": "versionItemId",
"value": "<long>",
"description": "(Required) ID of document version item"
}
]
}
},
"response": [
{
"name": "Successful operation",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/pdf"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/documents/:id/versions/:versionId/items/:versionItemId/download",
"host": [
"{{baseUrl}}"
],
"path": [
"documents",
":id",
"versions",
":versionId",
"items",
":versionItemId",
"download"
],
"variable": [
{
"key": "id"
},
{
"key": "versionId"
},
{
"key": "versionItemId"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "xml",
"header": [
{
"key": "Content-Type",
"value": "text/xml"
}
],
"cookie": [
],
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<element>(string)</element>"
},
{
"name": "Document Version does not exist",
"originalRequest": {
"method": "GET",
"header": [
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/documents/:id/versions/:versionId/items/:versionItemId/download",
"host": [
"{{baseUrl}}"
],
"path": [
"documents",
":id",
"versions",
":versionId",
"items",
":versionItemId",
"download"
],
"variable": [
{
"key": "id"
},
{
"key": "versionId"
},
{
"key": "versionItemId"
}
]
}
},
"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}}/documents/:id/versions/:versionId/items/:versionItemId/download",
"host": [
"{{baseUrl}}"
],
"path": [
"documents",
":id",
"versions",
":versionId",
"items",
":versionItemId",
"download"
],
"variable": [
{
"key": "id"
},
{
"key": "versionId"
},
{
"key": "versionItemId"
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "text",
"header": [
],
"cookie": [
],
"body": ""
}
]
}