Chilkat Online Tools

SQL Server / PandaDoc API Reference / Update Contact

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.

    -- {
    --   "first_name": "test1",
    --   "last_name": "test1",
    --   "company": "test1",
    --   "job_title": "test1",
    --   "phone": "test1",
    --   "country": "test1",
    --   "state": "test1",
    --   "street_address": "test1",
    --   "city": "test1",
    --   "postal_code": "test1"
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'first_name', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'last_name', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'company', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'job_title', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'phone', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'state', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'street_address', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'city', 'test1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'postal_code', 'test1'

    -- Adds the "Authorization: Bearer {{access_token}}" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '{{access_token}}'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PATCH', 'https://api.pandadoc.com/public/v1/contacts/{{contact_id}}/', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    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
        EXEC @hr = sp_OADestroy @sbRequestBody
        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
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X PATCH
	-H "Authorization: API-Key {{api_key}}"
	-H "Authorization: Bearer {{access_token}}"
	-d '{
    "first_name": "test1",
    "last_name": "test1",
    "company": "test1",
    "job_title": "test1",
    "phone": "test1",
    "country":"test1",
    "state":"test1",
    "street_address":"test1",
    "city":"test1",
    "postal_code":"test1"
}'
https://api.pandadoc.com/public/v1/contacts/{{contact_id}}/

Postman Collection Item JSON

{
  "name": "Update Contact",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Authorization",
        "value": "API-Key {{api_key}}",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{access_token}}",
        "type": "text",
        "disabled": true
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"first_name\": \"test1\",\n    \"last_name\": \"test1\",\n    \"company\": \"test1\",\n    \"job_title\": \"test1\",\n    \"phone\": \"test1\",\n    \"country\":\"test1\",\n    \"state\":\"test1\",\n    \"street_address\":\"test1\",\n    \"city\":\"test1\",\n    \"postal_code\":\"test1\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.pandadoc.com/public/v1/contacts/{{contact_id}}/",
      "protocol": "https",
      "host": [
        "api",
        "pandadoc",
        "com"
      ],
      "path": [
        "public",
        "v1",
        "contacts",
        "{{contact_id}}",
        ""
      ]
    }
  },
  "response": [
  ]
}