Chilkat Online Tools

Foxpro / easybill REST API / Create attachment

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loReq
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcCreated_at
LOCAL lcCustomer_id
LOCAL lcDocument_id
LOCAL lcFile_name
LOCAL lcId
LOCAL lcProject_id
LOCAL lcSize

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.HttpRequest')
loReq = CreateObject('Chilkat.HttpRequest')
loReq.HttpVerb = "POST"
loReq.Path = "/rest/v1/attachments"
loReq.ContentType = "multipart/form-data"
loReq.AddParam("file","<string>")

loReq.AddHeader("Authorization","{{apiKey}}")
loReq.AddHeader("Accept","application/json")

loResp = loHttp.SynchronousRequest("api.easybill.de",443,1,loReq)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loReq
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loReq
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

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

* {
*   "created_at": "<date>",
*   "customer_id": null,
*   "document_id": null,
*   "file_name": "<string>",
*   "id": "<long>",
*   "project_id": null,
*   "size": "<integer>"
* }

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

lcCreated_at = loJResp.StringOf("created_at")
lcCustomer_id = loJResp.StringOf("customer_id")
lcDocument_id = loJResp.StringOf("document_id")
lcFile_name = loJResp.StringOf("file_name")
lcId = loJResp.StringOf("id")
lcProject_id = loJResp.StringOf("project_id")
lcSize = loJResp.StringOf("size")

RELEASE loHttp
RELEASE loReq
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -X POST
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: multipart/form-data"
	-H "Accept: application/json"
	--form 'file=<string>'
https://api.easybill.de/rest/v1/attachments

Postman Collection Item JSON

{
  "name": "Create attachment",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "multipart/form-data"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "file",
          "value": "<string>",
          "description": "(Required) ",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{baseUrl}}/attachments",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "attachments"
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "multipart/form-data"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "file",
              "value": "<string>",
              "description": "(Required) ",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/attachments",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "attachments"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"created_at\": \"<date>\",\n  \"customer_id\": null,\n  \"document_id\": null,\n  \"file_name\": \"<string>\",\n  \"id\": \"<long>\",\n  \"project_id\": null,\n  \"size\": \"<integer>\"\n}"
    },
    {
      "name": "Too Many Requests",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "multipart/form-data"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "file",
              "value": "<string>",
              "description": "(Required) ",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/attachments",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "attachments"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}