Chilkat Online Tools

Xojo / PandaDoc API Reference / Create Attachment

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

Dim req As New Chilkat.HttpRequest
req.HttpVerb = "POST"
req.Path = "/public/v1/documents/{{document_id}}/attachments/"
req.ContentType = "multipart/form-data"
success = req.AddFileForUpload2("file"," path to file","application/octet-stream")

req.AddHeader "Authorization","API-Key {{api_key}}"
req.AddHeader "Expect","100-continue"

Dim resp As Chilkat.HttpResponse
resp = http.SynchronousRequest("api.pandadoc.com",443,True,req)
If (http.LastMethodSuccess = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

System.DebugLog(Str(resp.StatusCode))
System.DebugLog(resp.BodyStr)

Curl Command

curl -X POST
	-H "Authorization: Bearer {{access_token}}"
	-H "Authorization: API-Key {{api_key}}"
	--form 'file=@"/path/to/file"'
https://api.pandadoc.com/public/v1/documents/{{document_id}}/attachments/

Postman Collection Item JSON

{
  "name": "Create Attachment",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "if (jsonData.uuid !== undefined) {",
          "    postman.setEnvironmentVariable(\"attachment_id\", jsonData.uuid);",
          "}"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{access_token}}",
        "type": "text",
        "disabled": true
      },
      {
        "key": "Authorization",
        "value": "API-Key {{api_key}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "file",
          "type": "file",
          "src": [
          ]
        },
        {
          "key": "name",
          "value": "File Test Name",
          "type": "text",
          "disabled": true
        }
      ]
    },
    "url": {
      "raw": "https://api.pandadoc.com/public/v1/documents/{{document_id}}/attachments/",
      "protocol": "https",
      "host": [
        "api",
        "pandadoc",
        "com"
      ],
      "path": [
        "public",
        "v1",
        "documents",
        "{{document_id}}",
        "attachments",
        ""
      ]
    }
  },
  "response": [
  ]
}