Chilkat Online Tools

C / PandaDoc API Reference / Create Document in a Folder

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;

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

    http = CkHttp_Create();

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

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

    // {
    //   "name": "API Sample Document from PandaDoc Template",
    //   "template_uuid": "{{template_id}}",
    //   "folder_uuid": "{{documents_folder_uuid}}",
    //   "recipients": [
    //     {
    //       "email": "{{recipient_email}}",
    //       "first_name": "Jane",
    //       "last_name": "Roe",
    //       "role": "user"
    //     }
    //   ],
    //   "tokens": [
    //     {
    //       "name": "Favorite.Pet",
    //       "value": "Panda"
    //     }
    //   ],
    //   "fields": {
    //     "Favorite.Color": {
    //       "value": "PandaDoc green"
    //     },
    //     "Delivery": {
    //       "value": "Same Day Delivery"
    //     },
    //     "Like": {
    //       "value": true
    //     },
    //     "Date": {
    //       "value": "2019-12-31T00:00:00.000Z"
    //     }
    //   },
    //   "metadata": {
    //     "opp_id": "123456",
    //     "my_favorite_pet": "Panda"
    //   },
    //   "tags": [
    //     "created_via_api",
    //     "test_document"
    //   ],
    //   "pricing_tables": [
    //     {
    //       "name": "PricingTable1",
    //       "options": {
    //         "currency": "USD",
    //         "discount": {
    //           "is_global": true,
    //           "type": "absolute",
    //           "name": "Global Discount",
    //           "value": 2.26
    //         }
    //       },
    //       "sections": [
    //         {
    //           "title": "Sample Section",
    //           "default": true,
    //           "rows": [
    //             {
    //               "options": {
    //                 "optional": true,
    //                 "optional_selected": true,
    //                 "qty_editable": true
    //               },
    //               "data": {
    //                 "name": "Toy Panda",
    //                 "description": "Fluffy!",
    //                 "price": 10,
    //                 "qty": 3,
    //                 "tax_first": {
    //                   "value": 7.5,
    //                   "type": "percent"
    //                 }
    //               },
    //               "custom_fields": {
    //                 "Fluffiness": "5 / 5"
    //               }
    //             }
    //           ]
    //         }
    //       ]
    //     }
    //   ]
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"name","API Sample Document from PandaDoc Template");
    CkJsonObject_UpdateString(json,"template_uuid","{{template_id}}");
    CkJsonObject_UpdateString(json,"folder_uuid","{{documents_folder_uuid}}");
    CkJsonObject_UpdateString(json,"recipients[0].email","{{recipient_email}}");
    CkJsonObject_UpdateString(json,"recipients[0].first_name","Jane");
    CkJsonObject_UpdateString(json,"recipients[0].last_name","Roe");
    CkJsonObject_UpdateString(json,"recipients[0].role","user");
    CkJsonObject_UpdateString(json,"tokens[0].name","Favorite.Pet");
    CkJsonObject_UpdateString(json,"tokens[0].value","Panda");
    CkJsonObject_UpdateString(json,"fields.\"Favorite.Color\".value","PandaDoc green");
    CkJsonObject_UpdateString(json,"fields.Delivery.value","Same Day Delivery");
    CkJsonObject_UpdateBool(json,"fields.Like.value",TRUE);
    CkJsonObject_UpdateString(json,"fields.Date.value","2019-12-31T00:00:00.000Z");
    CkJsonObject_UpdateString(json,"metadata.opp_id","123456");
    CkJsonObject_UpdateString(json,"metadata.my_favorite_pet","Panda");
    CkJsonObject_UpdateString(json,"tags[0]","created_via_api");
    CkJsonObject_UpdateString(json,"tags[1]","test_document");
    CkJsonObject_UpdateString(json,"pricing_tables[0].name","PricingTable1");
    CkJsonObject_UpdateString(json,"pricing_tables[0].options.currency","USD");
    CkJsonObject_UpdateBool(json,"pricing_tables[0].options.discount.is_global",TRUE);
    CkJsonObject_UpdateString(json,"pricing_tables[0].options.discount.type","absolute");
    CkJsonObject_UpdateString(json,"pricing_tables[0].options.discount.name","Global Discount");
    CkJsonObject_UpdateNumber(json,"pricing_tables[0].options.discount.value","2.26");
    CkJsonObject_UpdateString(json,"pricing_tables[0].sections[0].title","Sample Section");
    CkJsonObject_UpdateBool(json,"pricing_tables[0].sections[0].default",TRUE);
    CkJsonObject_UpdateBool(json,"pricing_tables[0].sections[0].rows[0].options.optional",TRUE);
    CkJsonObject_UpdateBool(json,"pricing_tables[0].sections[0].rows[0].options.optional_selected",TRUE);
    CkJsonObject_UpdateBool(json,"pricing_tables[0].sections[0].rows[0].options.qty_editable",TRUE);
    CkJsonObject_UpdateString(json,"pricing_tables[0].sections[0].rows[0].data.name","Toy Panda");
    CkJsonObject_UpdateString(json,"pricing_tables[0].sections[0].rows[0].data.description","Fluffy!");
    CkJsonObject_UpdateInt(json,"pricing_tables[0].sections[0].rows[0].data.price",10);
    CkJsonObject_UpdateInt(json,"pricing_tables[0].sections[0].rows[0].data.qty",3);
    CkJsonObject_UpdateNumber(json,"pricing_tables[0].sections[0].rows[0].data.tax_first.value","7.5");
    CkJsonObject_UpdateString(json,"pricing_tables[0].sections[0].rows[0].data.tax_first.type","percent");
    CkJsonObject_UpdateString(json,"pricing_tables[0].sections[0].rows[0].custom_fields.Fluffiness","5 / 5");

    CkHttp_SetRequestHeader(http,"Authorization","API-Key {{api_key}}");
    CkHttp_SetRequestHeader(http,"Content-Type","application/json");

    resp = CkHttp_PostJson3(http,"https://api.pandadoc.com/public/v1/documents","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer {{access_token}}"
	-H "Authorization: API-Key {{api_key}}"
	-H "Content-Type: application/json"
	-d '{  
    "name": "API Sample Document from PandaDoc Template",
    "template_uuid": "{{template_id}}",
    "folder_uuid": "{{documents_folder_uuid}}",
    "recipients": [  
        {  
            "email": "{{recipient_email}}",
            "first_name": "Jane",
            "last_name": "Roe",
            "role": "user"
        }
    ],
    "tokens": [  
        {  
            "name": "Favorite.Pet",
            "value": "Panda"
        }
    ],
    "fields": {  
        "Favorite.Color": {  
            "value": "PandaDoc green"
        },
        "Delivery": {
        	"value": "Same Day Delivery"
        },
        "Like": {
        	"value": true
        },
        "Date": {
        	"value": "2019-12-31T00:00:00.000Z"
        }
    },
    "metadata":{  
        "opp_id": "123456",
        "my_favorite_pet": "Panda"
    },
    "tags": [
        "created_via_api",
        "test_document"
	], 
    "pricing_tables": [  
        {  
            "name": "PricingTable1",
            "options": {  
                "currency": "USD",
                "discount": {  
                    "is_global": true,
                    "type": "absolute",
                    "name": "Global Discount",
                    "value": 2.26
                }
            },
            "sections": [  
                {  
                    "title": "Sample Section",
                    "default": true,
                    "rows": [  
                        {  
                            "options": {  
                                "optional": true,
                                "optional_selected": true,
                                "qty_editable": true
                            },
                            "data":{  
                                "name": "Toy Panda",
                                "description": "Fluffy!",
                                "price": 10,
                                "qty": 3,
                                "tax_first": {  
                                    "value": 7.5,
                                    "type": "percent"
                                }
                            },
                            "custom_fields": {  
                                "Fluffiness": "5 / 5"
                            }
                        }
                    ]
                }
            ]
        }
    ]
}'
https://api.pandadoc.com/public/v1/documents

Postman Collection Item JSON

{
  "name": "Create Document in a Folder",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "if (jsonData.uuid !== undefined) {",
          "    postman.setEnvironmentVariable(\"document_id\", jsonData.uuid);",
          "}"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{access_token}}",
        "disabled": true
      },
      {
        "key": "Authorization",
        "value": "API-Key {{api_key}}",
        "type": "text"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{  \n    \"name\": \"API Sample Document from PandaDoc Template\",\n    \"template_uuid\": \"{{template_id}}\",\n    \"folder_uuid\": \"{{documents_folder_uuid}}\",\n    \"recipients\": [  \n        {  \n            \"email\": \"{{recipient_email}}\",\n            \"first_name\": \"Jane\",\n            \"last_name\": \"Roe\",\n            \"role\": \"user\"\n        }\n    ],\n    \"tokens\": [  \n        {  \n            \"name\": \"Favorite.Pet\",\n            \"value\": \"Panda\"\n        }\n    ],\n    \"fields\": {  \n        \"Favorite.Color\": {  \n            \"value\": \"PandaDoc green\"\n        },\n        \"Delivery\": {\n        \t\"value\": \"Same Day Delivery\"\n        },\n        \"Like\": {\n        \t\"value\": true\n        },\n        \"Date\": {\n        \t\"value\": \"2019-12-31T00:00:00.000Z\"\n        }\n    },\n    \"metadata\":{  \n        \"opp_id\": \"123456\",\n        \"my_favorite_pet\": \"Panda\"\n    },\n    \"tags\": [\n        \"created_via_api\",\n        \"test_document\"\n\t], \n    \"pricing_tables\": [  \n        {  \n            \"name\": \"PricingTable1\",\n            \"options\": {  \n                \"currency\": \"USD\",\n                \"discount\": {  \n                    \"is_global\": true,\n                    \"type\": \"absolute\",\n                    \"name\": \"Global Discount\",\n                    \"value\": 2.26\n                }\n            },\n            \"sections\": [  \n                {  \n                    \"title\": \"Sample Section\",\n                    \"default\": true,\n                    \"rows\": [  \n                        {  \n                            \"options\": {  \n                                \"optional\": true,\n                                \"optional_selected\": true,\n                                \"qty_editable\": true\n                            },\n                            \"data\":{  \n                                \"name\": \"Toy Panda\",\n                                \"description\": \"Fluffy!\",\n                                \"price\": 10,\n                                \"qty\": 3,\n                                \"tax_first\": {  \n                                    \"value\": 7.5,\n                                    \"type\": \"percent\"\n                                }\n                            },\n                            \"custom_fields\": {  \n                                \"Fluffiness\": \"5 / 5\"\n                            }\n                        }\n                    ]\n                }\n            ]\n        }\n    ]\n}"
    },
    "url": {
      "raw": "https://api.pandadoc.com/public/v1/documents",
      "protocol": "https",
      "host": [
        "api",
        "pandadoc",
        "com"
      ],
      "path": [
        "public",
        "v1",
        "documents"
      ]
    },
    "description": "Provide value to variables: template_id and documents_folder_uuid ([Postman environments](https://www.getpostman.com/docs/postman/environments_and_globals/manage_environments) is great for it).\n\nFor details and the sample template go to [https://developers.pandadoc.com/v1/reference#create-document-from-pandadoc-template](https://developers.pandadoc.com/v1/reference#create-document-from-pandadoc-template).\n\nFor details of document creation in general go to [https://developers.pandadoc.com/v1/reference#new-document](https://developers.pandadoc.com/v1/reference#new-document)."
  },
  "response": [
  ]
}