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
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.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.
-- {
-- "data": [
-- {
-- "Owner": {
-- "id": "{{user-id}}"
-- },
-- "Account_Name": {
-- "id": "{{account-id}}"
-- },
-- "Vendor_Name": {
-- "id": "{{vendor-id}}"
-- },
-- "Email": "newcrmapi@zoho.com",
-- "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
-- "Mailing_Zip": "Mailing_Zip",
-- "Reports_To": "Reports_To",
-- "Other_Phone": "988844559",
-- "Mailing_State": "Mailing_State",
-- "Twitter": "Twitter",
-- "Other_Zip": "Other_Zip",
-- "Mailing_Street": "Mailing_Street",
-- "Other_State": "Other_State",
-- "Salutation": "Mrs.",
-- "Other_Country": "Other_Country",
-- "First_Name": "First_Name",
-- "Asst_Phone": "988844559",
-- "Department": "Department",
-- "Skype_ID": "Skype_ID",
-- "Assistant": "Assistant",
-- "Phone": "988844559",
-- "Mailing_Country": "Mailing_Country",
-- "Email_Opt_Out": true,
-- "Date_of_Birth": "2018-01-25",
-- "Mailing_City": "Mailing_City",
-- "Other_City": "Other_City",
-- "Title": "Title",
-- "Other_Street": "Other_Street",
-- "Mobile": "988844559",
-- "Home_Phone": "988844559",
-- "Last_Name": "Last_Name",
-- "Lead_Source": "Cold Call",
-- "Fax": "Fax",
-- "Secondary_Email": "newcrmapi@zoho.com"
-- }
-- ]
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Owner.id', '{{user-id}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Account_Name.id', '{{account-id}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Vendor_Name.id', '{{vendor-id}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Email', 'newcrmapi@zoho.com'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Description', 'Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Mailing_Zip', 'Mailing_Zip'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Reports_To', 'Reports_To'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Other_Phone', '988844559'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Mailing_State', 'Mailing_State'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Twitter', 'Twitter'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Other_Zip', 'Other_Zip'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Mailing_Street', 'Mailing_Street'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Other_State', 'Other_State'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Salutation', 'Mrs.'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Other_Country', 'Other_Country'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].First_Name', 'First_Name'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Asst_Phone', '988844559'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Department', 'Department'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Skype_ID', 'Skype_ID'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Assistant', 'Assistant'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Phone', '988844559'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Mailing_Country', 'Mailing_Country'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'data[0].Email_Opt_Out', 1
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Date_of_Birth', '2018-01-25'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Mailing_City', 'Mailing_City'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Other_City', 'Other_City'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Title', 'Title'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Other_Street', 'Other_Street'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Mobile', '988844559'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Home_Phone', '988844559'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Last_Name', 'Last_Name'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Lead_Source', 'Cold Call'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Fax', 'Fax'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Secondary_Email', 'newcrmapi@zoho.com'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{authorization-token}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/crm/v2/Contacts', '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: {{authorization-token}}"
-H "Content-Type: application/json"
-d '{
"data": [
{
"Owner": {
"id": "{{user-id}}"
},
"Account_Name": {
"id": "{{account-id}}"
},
"Vendor_Name": {
"id": "{{vendor-id}}"
},
"Email": "newcrmapi@zoho.com",
"Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
"Mailing_Zip": "Mailing_Zip",
"Reports_To": "Reports_To",
"Other_Phone": "988844559",
"Mailing_State": "Mailing_State",
"Twitter": "Twitter",
"Other_Zip": "Other_Zip",
"Mailing_Street": "Mailing_Street",
"Other_State": "Other_State",
"Salutation": "Mrs.",
"Other_Country": "Other_Country",
"First_Name": "First_Name",
"Asst_Phone": "988844559",
"Department": "Department",
"Skype_ID": "Skype_ID",
"Assistant": "Assistant",
"Phone": "988844559",
"Mailing_Country": "Mailing_Country",
"Email_Opt_Out": true,
"Date_of_Birth": "2018-01-25",
"Mailing_City": "Mailing_City",
"Other_City": "Other_City",
"Title": "Title",
"Other_Street": "Other_Street",
"Mobile": "988844559",
"Home_Phone": "988844559",
"Last_Name": "Last_Name",
"Lead_Source": "Cold Call",
"Fax": "Fax",
"Secondary_Email": "newcrmapi@zoho.com"
}
]
}'
https://domain.com/crm/v2/Contacts
Postman Collection Item JSON
{
"name": "Contacts",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{authorization-token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"data\": [\n\t\t{\n\t\t\t\"Owner\": {\n\t\t\t\t\"id\": \"{{user-id}}\"\n\t\t\t},\n\t\t\t\"Account_Name\": {\n\t\t\t\t\"id\": \"{{account-id}}\"\n\t\t\t},\n\t\t\t\"Vendor_Name\": {\n\t\t\t\t\"id\": \"{{vendor-id}}\"\n\t\t\t},\n\t\t\t\"Email\": \"newcrmapi@zoho.com\",\n\t\t\t\"Description\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n\t\t\t\"Mailing_Zip\": \"Mailing_Zip\",\n\t\t\t\"Reports_To\": \"Reports_To\",\n\t\t\t\"Other_Phone\": \"988844559\",\n\t\t\t\"Mailing_State\": \"Mailing_State\",\n\t\t\t\"Twitter\": \"Twitter\",\n\t\t\t\"Other_Zip\": \"Other_Zip\",\n\t\t\t\"Mailing_Street\": \"Mailing_Street\",\n\t\t\t\"Other_State\": \"Other_State\",\n\t\t\t\"Salutation\": \"Mrs.\",\n\t\t\t\"Other_Country\": \"Other_Country\",\n\t\t\t\"First_Name\": \"First_Name\",\n\t\t\t\"Asst_Phone\": \"988844559\",\n\t\t\t\"Department\": \"Department\",\n\t\t\t\"Skype_ID\": \"Skype_ID\",\n\t\t\t\"Assistant\": \"Assistant\",\n\t\t\t\"Phone\": \"988844559\",\n\t\t\t\"Mailing_Country\": \"Mailing_Country\",\n\t\t\t\"Email_Opt_Out\": true,\n\t\t\t\"Date_of_Birth\": \"2018-01-25\",\n\t\t\t\"Mailing_City\": \"Mailing_City\",\n\t\t\t\"Other_City\": \"Other_City\",\n\t\t\t\"Title\": \"Title\",\n\t\t\t\"Other_Street\": \"Other_Street\",\n\t\t\t\"Mobile\": \"988844559\",\n\t\t\t\"Home_Phone\": \"988844559\",\n\t\t\t\"Last_Name\": \"Last_Name\",\n\t\t\t\"Lead_Source\": \"Cold Call\",\n\t\t\t\"Fax\": \"Fax\",\n\t\t\t\"Secondary_Email\": \"newcrmapi@zoho.com\"\n\t\t}\n\t]\n}"
},
"url": {
"raw": "{{api-domain}}/crm/v2/Contacts",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Contacts"
]
},
"description": "To add new entities to a module."
},
"response": [
]
}