Chilkat Online Tools

Swift3 / PandaDoc API Reference / Create Attachment

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    let req = CkoHttpRequest()!
    req.httpVerb = "POST"
    req.path = "/public/v1/documents/{{document_id}}/attachments/"
    req.contentType = "multipart/form-data"
    success = req.addFile(forUpload2: "file", path: " path to file", contentType: "application/octet-stream")

    req.addHeader("Authorization", value: "API-Key {{api_key}}")
    req.addHeader("Expect", value: "100-continue")

    var resp: CkoHttpResponse? = http.synchronousRequest("api.pandadoc.com", port: 443, ssl: true, req: req)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

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