Chilkat Online Tools

DataFlex / PandaDoc API Reference / Create Document from PandaDoc Template

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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": "Simple API Sample Document from PandaDoc Template",
    //   "template_uuid": "{{template_id}}",
    //   "recipients": [
    //     {
    //       "email": "{{recipient_email}}",
    //       "first_name": "Josh",
    //       "last_name": "Ron",
    //       "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": {
    //     "my_favorite_pet": "Panda"
    //   },
    //   "tags": [
    //     "created_via_api",
    //     "test_document"
    //   ],
    //   "images": [
    //     {
    //       "name": "Image 1",
    //       "urls": [
    //         "https://s3.amazonaws.com/pd-static-content/public-docs/pandadoc-panda-bear.png"
    //       ]
    //     }
    //   ],
    //   "pricing_tables": [
    //     {
    //       "name": "Pricing Table 1",
    //       "options": {
    //         "discount": {
    //           "type": "absolute",
    //           "name": "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"
    //               }
    //             }
    //           ]
    //         }
    //       ]
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "name" "Simple API Sample Document from PandaDoc Template" To iSuccess
    Get ComUpdateString Of hoJson "template_uuid" "{{template_id}}" To iSuccess
    Get ComUpdateString Of hoJson "recipients[0].email" "{{recipient_email}}" To iSuccess
    Get ComUpdateString Of hoJson "recipients[0].first_name" "Josh" To iSuccess
    Get ComUpdateString Of hoJson "recipients[0].last_name" "Ron" To iSuccess
    Get ComUpdateString Of hoJson "recipients[0].role" "user" To iSuccess
    Get ComUpdateString Of hoJson "tokens[0].name" "Favorite.Pet" To iSuccess
    Get ComUpdateString Of hoJson "tokens[0].value" "Panda" To iSuccess
    Get ComUpdateString Of hoJson 'fields."Favorite.Color".value' "PandaDoc green" To iSuccess
    Get ComUpdateString Of hoJson "fields.Delivery.value" "Same Day Delivery" To iSuccess
    Get ComUpdateBool Of hoJson "fields.Like.value" True To iSuccess
    Get ComUpdateString Of hoJson "fields.Date.value" "2019-12-31T00:00:00.000Z" To iSuccess
    Get ComUpdateString Of hoJson "metadata.my_favorite_pet" "Panda" To iSuccess
    Get ComUpdateString Of hoJson "tags[0]" "created_via_api" To iSuccess
    Get ComUpdateString Of hoJson "tags[1]" "test_document" To iSuccess
    Get ComUpdateString Of hoJson "images[0].name" "Image 1" To iSuccess
    Get ComUpdateString Of hoJson "images[0].urls[0]" "https://s3.amazonaws.com/pd-static-content/public-docs/pandadoc-panda-bear.png" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].name" "Pricing Table 1" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].options.discount.type" "absolute" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].options.discount.name" "Discount" To iSuccess
    Get ComUpdateNumber Of hoJson "pricing_tables[0].options.discount.value" "2.26" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].sections[0].title" "Sample Section" To iSuccess
    Get ComUpdateBool Of hoJson "pricing_tables[0].sections[0].default" True To iSuccess
    Get ComUpdateBool Of hoJson "pricing_tables[0].sections[0].rows[0].options.optional" True To iSuccess
    Get ComUpdateBool Of hoJson "pricing_tables[0].sections[0].rows[0].options.optional_selected" True To iSuccess
    Get ComUpdateBool Of hoJson "pricing_tables[0].sections[0].rows[0].options.qty_editable" True To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].sections[0].rows[0].data.name" "Toy Panda" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].sections[0].rows[0].data.description" "Fluffy!" To iSuccess
    Get ComUpdateInt Of hoJson "pricing_tables[0].sections[0].rows[0].data.price" 10 To iSuccess
    Get ComUpdateInt Of hoJson "pricing_tables[0].sections[0].rows[0].data.qty" 3 To iSuccess
    Get ComUpdateNumber Of hoJson "pricing_tables[0].sections[0].rows[0].data.tax_first.value" "7.5" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].sections[0].rows[0].data.tax_first.type" "percent" To iSuccess
    Get ComUpdateString Of hoJson "pricing_tables[0].sections[0].rows[0].custom_fields.Fluffiness" "5 / 5" To iSuccess

    Send ComSetRequestHeader To hoHttp "Authorization" "API-Key {{api_key}}"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.pandadoc.com/public/v1/documents" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

Curl Command

curl -X POST
	-H "Authorization: Bearer {{access_token}}"
	-H "Authorization: API-Key {{api_key}}"
	-H "Content-Type: application/json"
	-d '{
    "name": "Simple API Sample Document from PandaDoc Template",
    "template_uuid": "{{template_id}}",
    "recipients": [
        {
            "email": "{{recipient_email}}",
            "first_name": "Josh",
            "last_name": "Ron",
            "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": {
        "my_favorite_pet": "Panda"
    },
    "tags": [
        "created_via_api",
        "test_document"
    ],
    "images": [
        {
            "name": "Image 1",
            "urls": [
                "https://s3.amazonaws.com/pd-static-content/public-docs/pandadoc-panda-bear.png"
            ]
        }
    ],
    "pricing_tables": [
        {
            "name": "Pricing Table 1",
            "options": {
                "discount": {
                    "type": "absolute",
                    "name": "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 from PandaDoc Template",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "if (jsonData.uuid !== undefined) {",
          "    postman.setEnvironmentVariable(\"document_id\", jsonData.uuid);",
          "}"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "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\": \"Simple API Sample Document from PandaDoc Template\",\n    \"template_uuid\": \"{{template_id}}\",\n    \"recipients\": [\n        {\n            \"email\": \"{{recipient_email}}\",\n            \"first_name\": \"Josh\",\n            \"last_name\": \"Ron\",\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            \"value\": \"Same Day Delivery\"\n        },\n        \"Like\": {\n            \"value\": true\n        },\n        \"Date\": {\n            \"value\": \"2019-12-31T00:00:00.000Z\"\n        }\n    },\n    \"metadata\": {\n        \"my_favorite_pet\": \"Panda\"\n    },\n    \"tags\": [\n        \"created_via_api\",\n        \"test_document\"\n    ],\n    \"images\": [\n        {\n            \"name\": \"Image 1\",\n            \"urls\": [\n                \"https://s3.amazonaws.com/pd-static-content/public-docs/pandadoc-panda-bear.png\"\n            ]\n        }\n    ],\n    \"pricing_tables\": [\n        {\n            \"name\": \"Pricing Table 1\",\n            \"options\": {\n                \"discount\": {\n                    \"type\": \"absolute\",\n                    \"name\": \"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 variable: template_id ([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": [
  ]
}