Chilkat Online Tools

SQL Server / PandaDoc API Reference / Create Document from PandaDoc Template (Full API Sample Document from PandaDoc Template)

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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": "Full API Sample Document from PandaDoc Template",
    --   "template_uuid": "{{template_id}}",
    --   "owner": {
    --     "membership_id": "{{membership_id}}"
    --   },
    --   "recipients": [
    --     {
    --       "email": "{{recipient_email}}",
    --       "first_name": "Josh",
    --       "last_name": "Ron",
    --       "role": "user",
    --       "signing_order": 1
    --     }
    --   ],
    --   "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",
    --       "data_merge": true,
    --       "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,
    --                 "Tax1": {
    --                   "value": 7.5,
    --                   "type": "percent"
    --                 }
    --               },
    --               "custom_fields": {
    --                 "Fluffiness": "5 / 5"
    --               }
    --             }
    --           ]
    --         }
    --       ]
    --     }
    --   ],
    --   "content_placeholders": [
    --     {
    --       "block_id": "{{block_id}}",
    --       "content_library_items": [
    --         {
    --           "id": "{{cli_id}}",
    --           "pricing_tables": [
    --             {
    --               "name": "Pricing Table 1",
    --               "data_merge": true,
    --               "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": "Placeholder Panda",
    --                         "Price": 10,
    --                         "QTY": 3
    --                       }
    --                     }
    --                   ]
    --                 }
    --               ]
    --             }
    --           ]
    --         },
    --         {
    --           "id": "{{cli_id_2}}",
    --           "recipients": [
    --             {
    --               "email": "john@example.com",
    --               "first_name": "John",
    --               "last_name": "Roe",
    --               "role": "Signer",
    --               "signing_order": 2
    --             }
    --           ],
    --           "fields": {
    --             "Date": {
    --               "value": "2019-12-31T00:00:00.000Z"
    --             }
    --           }
    --         }
    --       ]
    --     }
    --   ]
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'name', 'Full API Sample Document from PandaDoc Template'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'template_uuid', '{{template_id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'owner.membership_id', '{{membership_id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].email', '{{recipient_email}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].first_name', 'Josh'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].last_name', 'Ron'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].role', 'user'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'recipients[0].signing_order', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tokens[0].name', 'Favorite.Pet'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tokens[0].value', 'Panda'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'fields."Favorite.Color".value', 'PandaDoc green'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'fields.Delivery.value', 'Same Day Delivery'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'fields.Like.value', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'fields.Date.value', '2019-12-31T00:00:00.000Z'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'metadata.my_favorite_pet', 'Panda'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tags[0]', 'created_via_api'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tags[1]', 'test_document'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'images[0].name', 'Image 1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'images[0].urls[0]', 'https://s3.amazonaws.com/pd-static-content/public-docs/pandadoc-panda-bear.png'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].name', 'Pricing Table 1'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'pricing_tables[0].data_merge', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].options.discount.type', 'absolute'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].options.discount.name', 'Discount'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'pricing_tables[0].options.discount.value', '2.26'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].sections[0].title', 'Sample Section'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'pricing_tables[0].sections[0].default', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'pricing_tables[0].sections[0].rows[0].options.optional', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'pricing_tables[0].sections[0].rows[0].options.optional_selected', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'pricing_tables[0].sections[0].rows[0].options.qty_editable', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].sections[0].rows[0].data.Name', 'Toy Panda'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].sections[0].rows[0].data.Description', 'Fluffy!'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'pricing_tables[0].sections[0].rows[0].data.Price', 10
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'pricing_tables[0].sections[0].rows[0].data.QTY', 3
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'pricing_tables[0].sections[0].rows[0].data.Tax1.value', '7.5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].sections[0].rows[0].data.Tax1.type', 'percent'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pricing_tables[0].sections[0].rows[0].custom_fields.Fluffiness', '5 / 5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].block_id', '{{block_id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[0].id', '{{cli_id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].name', 'Pricing Table 1'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].data_merge', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].options.discount.type', 'absolute'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].options.discount.name', 'Discount'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].options.discount.value', '2.26'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].title', 'Sample Section'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].default', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].rows[0].options.optional', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].rows[0].options.optional_selected', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].rows[0].options.qty_editable', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].rows[0].data.Name', 'Placeholder Panda'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].rows[0].data.Price', 10
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'content_placeholders[0].content_library_items[0].pricing_tables[0].sections[0].rows[0].data.QTY', 3
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[1].id', '{{cli_id_2}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[1].recipients[0].email', 'john@example.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[1].recipients[0].first_name', 'John'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[1].recipients[0].last_name', 'Roe'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[1].recipients[0].role', 'Signer'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'content_placeholders[0].content_library_items[1].recipients[0].signing_order', 2
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content_placeholders[0].content_library_items[1].fields.Date.value', '2019-12-31T00:00:00.000Z'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'API-Key {{api_key}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.pandadoc.com/public/v1/documents', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer {{access_token}}"
	-H "Authorization: API-Key {{api_key}}"
	-H "Content-Type: application/json"
	-d '{
    "name": "Full API Sample Document from PandaDoc Template",
    "template_uuid": "{{template_id}}",
    "owner":{
        "membership_id":"{{membership_id}}"
    },
    "recipients": [
        {
            "email": "{{recipient_email}}",
            "first_name": "Josh",
            "last_name": "Ron",
            "role": "user",
            "signing_order": 1
        }
    ],
    "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",
            "data_merge":true,
            "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,
                                "Tax1": {
                                    "value": 7.5,
                                    "type": "percent"
                                }
                            },
                            "custom_fields": {
                                "Fluffiness": "5 / 5"
                            }
                        }
                    ]
                }
            ]
        }
    ],
    "content_placeholders": [
        {
            "block_id": "{{block_id}}",
            "content_library_items": [
                {
                    "id": "{{cli_id}}",
                    "pricing_tables": [
                        {
                            "name": "Pricing Table 1",
                            "data_merge":true,
                            "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": "Placeholder Panda",
                                                "Price": 10,
                                                "QTY": 3
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    "id": "{{cli_id_2}}",
                    "recipients": [
                        {
                            "email": "john@example.com",
                            "first_name": "John",
                            "last_name": "Roe",
                            "role": "Signer",
                            "signing_order": 2
                        }
                    ],
                    "fields": {
                        "Date": {
        	                "value": "2019-12-31T00:00:00.000Z"
                        }
                    }
                }
            ]
        }
    ]
}'
https://api.pandadoc.com/public/v1/documents

Postman Collection Item JSON

{
  "name": "Create Document from PandaDoc Template (Full API Sample 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\": \"Full API Sample Document from PandaDoc Template\",\n    \"template_uuid\": \"{{template_id}}\",\n    \"owner\":{\n        \"membership_id\":\"{{membership_id}}\"\n    },\n    \"recipients\": [\n        {\n            \"email\": \"{{recipient_email}}\",\n            \"first_name\": \"Josh\",\n            \"last_name\": \"Ron\",\n            \"role\": \"user\",\n            \"signing_order\": 1\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            \"data_merge\":true,\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                                \"Tax1\": {\n                                    \"value\": 7.5,\n                                    \"type\": \"percent\"\n                                }\n                            },\n                            \"custom_fields\": {\n                                \"Fluffiness\": \"5 / 5\"\n                            }\n                        }\n                    ]\n                }\n            ]\n        }\n    ],\n    \"content_placeholders\": [\n        {\n            \"block_id\": \"{{block_id}}\",\n            \"content_library_items\": [\n                {\n                    \"id\": \"{{cli_id}}\",\n                    \"pricing_tables\": [\n                        {\n                            \"name\": \"Pricing Table 1\",\n                            \"data_merge\":true,\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\": \"Placeholder Panda\",\n                                                \"Price\": 10,\n                                                \"QTY\": 3\n                                            }\n                                        }\n                                    ]\n                                }\n                            ]\n                        }\n                    ]\n                },\n                {\n                    \"id\": \"{{cli_id_2}}\",\n                    \"recipients\": [\n                        {\n                            \"email\": \"john@example.com\",\n                            \"first_name\": \"John\",\n                            \"last_name\": \"Roe\",\n                            \"role\": \"Signer\",\n                            \"signing_order\": 2\n                        }\n                    ],\n                    \"fields\": {\n                        \"Date\": {\n        \t                \"value\": \"2019-12-31T00:00:00.000Z\"\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": [
  ]
}