Chilkat Online Tools

DataFlex / PandaDoc API Reference / Create Contact

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.

    // {
    //   "email": "nobody@example.com",
    //   "first_name": "test",
    //   "last_name": "test",
    //   "company": "test",
    //   "job_title": "test",
    //   "phone": "test",
    //   "country": "test",
    //   "state": "test",
    //   "street_address": "test",
    //   "city": "test",
    //   "postal_code": "test"
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "email" "nobody@example.com" To iSuccess
    Get ComUpdateString Of hoJson "first_name" "test" To iSuccess
    Get ComUpdateString Of hoJson "last_name" "test" To iSuccess
    Get ComUpdateString Of hoJson "company" "test" To iSuccess
    Get ComUpdateString Of hoJson "job_title" "test" To iSuccess
    Get ComUpdateString Of hoJson "phone" "test" To iSuccess
    Get ComUpdateString Of hoJson "country" "test" To iSuccess
    Get ComUpdateString Of hoJson "state" "test" To iSuccess
    Get ComUpdateString Of hoJson "street_address" "test" To iSuccess
    Get ComUpdateString Of hoJson "city" "test" To iSuccess
    Get ComUpdateString Of hoJson "postal_code" "test" To iSuccess

    // Adds the "Authorization: Bearer {{access_token}}" header.
    Set ComAuthToken Of hoHttp To "{{access_token}}"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.pandadoc.com/public/v1/contacts/" "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: API-Key {{api_key}}"
	-H "Authorization: Bearer {{access_token}}"
	-d '{
    "email": "nobody@example.com",
    "first_name": "test",
    "last_name": "test",
    "company": "test",
    "job_title": "test",
    "phone": "test",
    "country":"test",
    "state":"test",
    "street_address":"test",
    "city":"test",
    "postal_code":"test"
}'
https://api.pandadoc.com/public/v1/contacts/

Postman Collection Item JSON

{
  "name": "Create Contact",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "if (jsonData.id !== undefined) {",
          "    postman.setEnvironmentVariable(\"contact_id\", jsonData.id);",
          "}"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "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    \"email\": \"nobody@example.com\",\n    \"first_name\": \"test\",\n    \"last_name\": \"test\",\n    \"company\": \"test\",\n    \"job_title\": \"test\",\n    \"phone\": \"test\",\n    \"country\":\"test\",\n    \"state\":\"test\",\n    \"street_address\":\"test\",\n    \"city\":\"test\",\n    \"postal_code\":\"test\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.pandadoc.com/public/v1/contacts/",
      "protocol": "https",
      "host": [
        "api",
        "pandadoc",
        "com"
      ],
      "path": [
        "public",
        "v1",
        "contacts",
        ""
      ]
    }
  },
  "response": [
  ]
}