Chilkat Online Tools

SQL Server / easybill REST API / Send 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
    DECLARE @iTmp0 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

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

    -- The following JSON is sent in the request body.

    -- {
    --   "to": "<string>",
    --   "cc": "<string>",
    --   "from": "<string>",
    --   "subject": "<string>",
    --   "message": "<string>",
    --   "date": "<date>",
    --   "send_by_self": "<boolean>",
    --   "send_with_attachment": "true",
    --   "document_file_type": "default",
    --   "post_send_type": "post_send_type_prio"
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'cc', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'from', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'subject', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'message', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'date', '<date>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'send_by_self', '<boolean>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'send_with_attachment', 'true'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'document_file_type', 'default'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'post_send_type', 'post_send_type_prio'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{apiKey}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.easybill.de/rest/v1/documents/:id/send/:type', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

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

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Response Body:'
        EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: application/json"
	-d '{
  "to": "<string>",
  "cc": "<string>",
  "from": "<string>",
  "subject": "<string>",
  "message": "<string>",
  "date": "<date>",
  "send_by_self": "<boolean>",
  "send_with_attachment": "true",
  "document_file_type": "default",
  "post_send_type": "post_send_type_prio"
}'
https://api.easybill.de/rest/v1/documents/:id/send/:type

Postman Collection Item JSON

{
  "name": "Send document",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"to\": \"<string>\",\n  \"cc\": \"<string>\",\n  \"from\": \"<string>\",\n  \"subject\": \"<string>\",\n  \"message\": \"<string>\",\n  \"date\": \"<date>\",\n  \"send_by_self\": \"<boolean>\",\n  \"send_with_attachment\": \"true\",\n  \"document_file_type\": \"default\",\n  \"post_send_type\": \"post_send_type_prio\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/documents/:id/send/:type",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "documents",
        ":id",
        "send",
        ":type"
      ],
      "variable": [
        {
          "key": "id",
          "value": "<long>",
          "description": "(Required) ID of document"
        },
        {
          "key": "type",
          "value": "fax",
          "description": "(Required) "
        }
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "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  \"to\": \"<string>\",\n  \"cc\": \"<string>\",\n  \"from\": \"<string>\",\n  \"subject\": \"<string>\",\n  \"message\": \"<string>\",\n  \"date\": \"<date>\",\n  \"send_by_self\": \"<boolean>\",\n  \"send_with_attachment\": \"true\",\n  \"document_file_type\": \"default\",\n  \"post_send_type\": \"post_send_type_prio\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/documents/:id/send/:type",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "documents",
            ":id",
            "send",
            ":type"
          ],
          "variable": [
            {
              "key": "id"
            },
            {
              "key": "type"
            }
          ]
        }
      },
      "status": "No Content",
      "code": 204,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Not found",
      "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  \"to\": \"<string>\",\n  \"cc\": \"<string>\",\n  \"from\": \"<string>\",\n  \"subject\": \"<string>\",\n  \"message\": \"<string>\",\n  \"date\": \"<date>\",\n  \"send_by_self\": \"<boolean>\",\n  \"send_with_attachment\": \"true\",\n  \"document_file_type\": \"default\",\n  \"post_send_type\": \"post_send_type_prio\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/documents/:id/send/:type",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "documents",
            ":id",
            "send",
            ":type"
          ],
          "variable": [
            {
              "key": "id"
            },
            {
              "key": "type"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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  \"to\": \"<string>\",\n  \"cc\": \"<string>\",\n  \"from\": \"<string>\",\n  \"subject\": \"<string>\",\n  \"message\": \"<string>\",\n  \"date\": \"<date>\",\n  \"send_by_self\": \"<boolean>\",\n  \"send_with_attachment\": \"true\",\n  \"document_file_type\": \"default\",\n  \"post_send_type\": \"post_send_type_prio\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/documents/:id/send/:type",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "documents",
            ":id",
            "send",
            ":type"
          ],
          "variable": [
            {
              "key": "id"
            },
            {
              "key": "type"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}