PHP cURL insertRecords example

PHP cURL insertRecords example

After trying to insert a Lead using the API documentation example (and subsequently banging my head against the wall for some time), then searching in the forums for examples to no avail, I decided to learn cURL, which is far simpler than I assumed.  Someone else in the forum asked for an example with cURL a while back, so I figured I'd post what worked (fairly simply) for me.

  1. //using cURL to get new ticket each time instead of setting up script to renew every 7 days

  2. $tick = curl_init('https://accounts.zoho.com/login');

  3. curl_setopt($tick, CURLOPT_VERBOSE, 1);

  4. curl_setopt($tick, CURLOPT_RETURNTRANSFER, 1);

  5. curl_setopt($tick, CURLOPT_POST, 1);

  6. $query = "LOGIN_ID=[[YOUR ID]]&PASSWORD=[[YOUR PASSWORD]]&FROM_AGENT=true&servicename=ZohoCRM&submit=Generate Ticket";

  7. curl_setopt($tick, CURLOPT_POSTFIELDS, $query);

  8. $getTick = curl_exec($tick);

  9. curl_close($tick);



  10. //generated a string, need to dig ticket out

  11. $tickInfo = (explode("\n",$getTick));

  12. foreach($tickInfo as $t) {

  13.     if (strstr($t,'TICKET=')) {

  14.         $ticket = end(explode('=',$t));

  15.     }

  16. }



  17. $api = 'YOUR API KEY';

  18. /*$xml is string of XML, formatted exactly like https://zohocrmapi.wiki.zoho.com/insertRecords-Method.html#Sample_Lead_XMLDATA*/



  19. //Initialize connection

  20. $ch = curl_init('https://crm.zoho.com/crm/private/xml/Leads/insertRecords');

  21. curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams

  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification

  23. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response)

  25. curl_setopt($ch, CURLOPT_POST, 1);//Regular post

  26. //Set post fields

  27. $query = "newFormat=1&apikey={$api}&ticket={$ticket}&xmlData={$xml}";

  28. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);// Set the request as a POST FIELD for curl.

  29. //Execute cUrl session

  30. $response = curl_exec($ch);

  31. curl_close($ch);
Let me know if it doesn't work from straight copy/paste - I removed some code that shouldn't be essential to the example that.

The documentation would definitely benefit from more extensive examples...

-David
www.lookdadcreative.com








    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts



                                                            • Sticky Posts

                                                            • Kaizen #222 - Client Script Support for Notes Related List

                                                              Hello everyone! Welcome to another week of Kaizen. The final Kaizen post of the year 2025 is here! With the new Client Script support for the Notes Related List, you can validate, enrich, and manage notes across modules. In this post, we’ll explore how
                                                            • Kaizen #217 - Actions APIs : Tasks

                                                              Welcome to another week of Kaizen! In last week's post we discussed Email Notifications APIs which act as the link between your Workflow automations and you. We have discussed how Zylker Cloud Services uses Email Notifications API in their custom dashboard.
                                                            • Kaizen #216 - Actions APIs : Email Notifications

                                                              Welcome to another week of Kaizen! For the last three weeks, we have been discussing Zylker's workflows. We successfully updated a dormant workflow, built a new one from the ground up and more. But our work is not finished—these automated processes are
                                                            • Kaizen #152 - Client Script Support for the new Canvas Record Forms

                                                              Hello everyone! Have you ever wanted to trigger actions on click of a canvas button, icon, or text mandatory forms in Create/Edit and Clone Pages? Have you ever wanted to control how elements behave on the new Canvas Record Forms? This can be achieved
                                                            • Kaizen #142: How to Navigate to Another Page in Zoho CRM using Client Script

                                                              Hello everyone! Welcome back to another exciting Kaizen post. In this post, let us see how you can you navigate to different Pages using Client Script. In this Kaizen post, Need to Navigate to different Pages Client Script ZDKs related to navigation A.


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner









                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                              • Recent Topics

                                                                                                              • Automatically Add Recurring Zoho Meeting Events to Zoho Calendar / Zoho Meeting Calendar

                                                                                                                Hello Zoho Meeting Team, Hope you are doing well. We would like to request an enhancement regarding recurring meetings created inside Zoho Meeting. At the moment, when we schedule a recurring meeting in Zoho Meeting, it does not appear in Zoho Calendar
                                                                                                              • Credit Management: #6 Tackling Common Mistakes in Credit Based Billing

                                                                                                                Businesses extend credit to build relationships, make buying easy, and drive more sales. But somewhere between extending and collecting, things begin to slip. A few late payments here and there, an overlooked invoice, and a backlog make cash flow feel
                                                                                                              • Updating Blueprint stage from my Deluge function

                                                                                                                Hi all, I need to update the blueprint stage. Its almost working, but ONLY if the current Deal stage is 'Closed Lost'. On any of my custom stages that Ive specified in the pipeline it doesnt work! My code: dealmap = Map(); deal_stage = deal.get("Stage");
                                                                                                              • Canvas: is it possible to have a fixed header?

                                                                                                                Hello. Does Canvas provide the option to have a fixed header, similar to the standard view? It would also be interesting for other parts of the interface, like the header or sidebar of the tab section. Thanks!
                                                                                                              • Limited layout rules in a module

                                                                                                                There is a limit of 10 layout rules per module. Is there a way to get that functionality through different customization or workflow + custom function (easily accessible), etc. Having just 10 is limiting especially if module contains a lot of data. Are
                                                                                                              • Using Contains as a filter

                                                                                                                We are using Zoho Reports, ServiceDesk Plus analytics. I do not see how to create a report filter using Contains comparison of a string values, is one string contained in another. For example, Task Title contains the word Monitor. Is this possible in Zoho Reports?  This reporting feature is available in SDP reporting. Thanks in advance, Craig Rice
                                                                                                              • Set off Unearned Revenue

                                                                                                                Hi, I would like to get a clarification on the below. I have an opening balance of BD.725/- in my Unearned Revenue A/c which includes the overpayments of 6 clients. No One of my clients settled his invoices by paying the value of the invoice less the
                                                                                                              • How Zoho Desk contributes to the art of savings

                                                                                                                Remember the first time your grandmother gave you cash for a birthday or New Year's gift, Christmas gift, or any special day? You probably tucked that money safely into a piggy bank, waiting for the day you could buy something precious or something you
                                                                                                              • Add Webhook Response Module to Zoho Flow

                                                                                                                Hi Zoho Flow Team, We’d like to request a Webhook Response capability for Zoho Flow that can return a dynamic, computed reply to the original webhook caller after / during the flow runs. What exists today Zoho Flow’s webhook trigger can send custom acknowledgements
                                                                                                              • When moments in customer support get "spooky"

                                                                                                                It’s Halloween again! Halloween is celebrated with spooky symbols and meanings based on history and traditions, with each region adding its own special touch. While we were kids, we would dress up in costumes along with friends, attend parties, and enjoy
                                                                                                              • How to backdate record payment for the invoice

                                                                                                                I would like to record a payment which happened 2 days ago, but I am not able to select any date later than today. I backdated the invoice, too, but it doesn't change anything
                                                                                                              • Questions about Zoho mail

                                                                                                                Hello, I had up until recently, the free version. I got a warning message that said, "The user account (Redacted email address) 6.02 GB in your organization is almost nearing the allocated storage of 5.00 GB. If the storage exceeds the allowed limit,
                                                                                                              • How can I delete duplicate transactions?

                                                                                                                I want to delete the duplicates not simply exclude them. I have duplicates, because I had automatic bank feeds turned on (had to make sure this critical functionality was working before migrating to Zoho). Now when I import my csv's exported from Wave,
                                                                                                              • Multiple email addresses

                                                                                                                Multiple email addresses: I understand there is the ability to add an additional email field to a contact, but the functionality here needs to be drastically revised. Currently, this second email address does not log under the contact email history, nor is it available as a send address when using the Send Mail button within CRM. We recently migrated from GoldMine. I hate GoldMine, but there is one thing they did well: Email. I suggest copying them. Change the email field to an editable picklist,
                                                                                                              • ViewID and Zoho Desk API

                                                                                                                I'm looking at the documentation for Listing contacts and it looks like you can filter by ViewID. I assume this is views created in a department or all departments. Is this correct? And if so, how do I find the ViewID for that view? EDIT: I see the view
                                                                                                              • Ability to Link Reported Issues from Zoho Desk to Specific Tasks or Subtasks in Zoho Projects

                                                                                                                Hi Zoho Desk Team, Hope you're doing well. When reporting a bug from Zoho Desk to Zoho Projects, we’ve noticed that it’s currently not possible to select an existing task or subtask to associate the issue with. However, when working directly inside Zoho
                                                                                                              • Print Tickets

                                                                                                                We have field engineers who visit customers. We would like the option to print a job sheet with full details of the job and account/contact details.
                                                                                                              • Zoho Desk integration with Power BI

                                                                                                                Hi, I want to be able to create a Power BI report which has live updates of ticket data from zoho desk, is this possile at all? Thanks Jack
                                                                                                              • Ability to Attach Images When Reporting Issues to Zoho Projects from Zoho Desk

                                                                                                                Hi Zoho Desk Team, Hope you’re doing well. We’re using the Zoho Desk–Zoho Projects integration to report bugs directly from support tickets into the Zoho Projects issue tracker. This integration is extremely useful and helps us maintain smooth coordination
                                                                                                              • Ability to Choose Task List and Add Subtasks When Creating Tasks from Zoho Desk

                                                                                                                Hi Zoho Desk Team, Hope you’re doing well. We’re using the Zoho Desk–Zoho Projects integration to seamlessly connect customer tickets with project tasks. While the integration works great overall, we noticed two important limitations that affect our workflow
                                                                                                              • Sync Task Status from Zoho Projects to Zoho Desk

                                                                                                                Hi Zoho Desk Team, Hope you’re doing well. We’re actively using the Zoho Desk–Zoho Projects integration, which helps our support and project teams stay aligned. However, we noticed that when we change a task’s status in Zoho Projects, the change is not
                                                                                                              • Default/Private Departments in Zoho Desk

                                                                                                                1) How does one configure a department to be private? 2) Also, how does one change the default department? 1) On the list of my company's Zoho Departments, I see that we have a default department, but I am unable to choose which department should be default. 2) From the Zoho documentation I see that in order to create a private department, one should uncheck "Display in customer portal" on the Add Department screen. However, is there a way to change this setting after the department has been created?
                                                                                                              • Zoho CRM IP Addresses to Whitelist

                                                                                                                We were told to whitelist IP addresses from Zoho CRM.  (CRM, not Zoho Mail.) What is the current list of IP Addresses to whitelist for outbound mail? Is there a website where these IP addresses are published and updated?  Everything I could find is over
                                                                                                              • Color of Text Box Changes

                                                                                                                Sometimes I find the color of text boxes changed to a different color. This seems to happen when I reopen the same slide deck later. In the image that I am attaching, you see that the colors of the whole "virus," the "irology" part of "virology," and
                                                                                                              • The difference between Zoho Marketing Automation and Zoho Campaigns

                                                                                                                Greetings Marketers! This post aims to differentiate between Zoho Marketing Automation and Zoho Campaigns. By the time you get to the end of the post, you will be able to choose a product that objectively suits you. What is Zoho Marketing Automation?
                                                                                                              • How to use Rollup Summary in a Formula Field?

                                                                                                                I created a Rollup Summary (Decimal) field in my module, and it shows values correctly. When I try to reference it in a Formula Field (e.g. ${Deals.Partners_Requested} - ${Deals.Partners_Paid}), I get the error that the field can’t be found. Is it possible
                                                                                                              • Zoho Mail Android app update - View emails shared via Permalink on the app.

                                                                                                                Hello everyone! In the latest version(v2.8.2) of the Zoho Mail Android app update, we have brought in support to access the emails shared via permalink within the app. Earlier, when you click the permalink of an email, you'll be redirected to a mobile
                                                                                                              • Let us view and export the full price books data from CRM

                                                                                                                I quote out of CRM, some of my clients have specialised pricing for specific products - therefore we use Price Books to manage these special prices. I can only see the breakdown of the products listed in the price book and the specialised pricing for
                                                                                                              • How to create a Zoho Mail extension similar to Outlook's OnSend add-in?

                                                                                                                Hi, I want to create a Zoho Mail extension similar to Outlook’s OnSend add-in. The extension should: Let the user select headers and footers from a taskpane while composing an email. When the user clicks Send, the extension should: Automatically insert
                                                                                                              • How to display Motivator components in Zoho CRM home page ?

                                                                                                                Hello, I created KPI's, games and so but I want to be able to see my KPI's and my tasks at the same time. Is this possible to display Motivator components in Zoho CRM home page ? Has someone any idea ? Thanks for your help.
                                                                                                              • Introducing Record Summary: smarter insights at your fingertips

                                                                                                                Hello everyone, We’re excited to introduce the Record Summary feature. This powerful addition makes use of Zia to simplify how you interact with your CRM data, providing a seamless, consolidated view of critical record information. Scrolling through the
                                                                                                              • Delegates should be able to delete expenses

                                                                                                                I understand the data integrity of this request. It would be nice if there was a toggle switch in the Policy setting that would allow a delegate to delete expenses from their managers account. Some managers here never touch their expense reports, and
                                                                                                              • Function #9: Copy attachments of Sales Order to Purchase Order on conversion

                                                                                                                This week, we have written a custom function that automatically copies the attachments uploaded for a sales order to the corresponding purchase order after you convert it. Here's how to configure it in your Zoho Books organization. Custom Function: Hit
                                                                                                              • Kaizen #8 - Handling Recurrence and Participants in the Events Module via API

                                                                                                                Hello everyone! We are back this week with an exciting post—Handling recurrence and participants in the Events module through API. First things first—What is the Events module? "Events" is a part of the Activities module in Zoho CRM.  An event is an activity that happens at a given place and time. You can find Events on the user's Zoho CRM's home page, Activities home page, Calendar, and in other related records. What are the types of Events? Events are of two types—Recurring and non-recurring events.
                                                                                                              • Marketer’s Space - Get Holiday-Ready with Zoho Campaigns

                                                                                                                Hello marketers, Welcome back to another post in Marketer’s Space! Q4 is packed with opportunities to connect with your audience - from Halloween, Black Friday, and Cyber Monday, to Thanksgiving, Christmas, and New Year. In this post, we’ll look at how
                                                                                                              • Personalized demo

                                                                                                                can I know more about the personalized demo we are construction company and
                                                                                                              • Can I collect email addresses in a form??

                                                                                                                Can I add new subscribers to my email list (hosted in FloDesk) when they check a box and add their email address on a Zoho form?
                                                                                                              • Zoho CRM Android app updates: Kiosk and multiple file upload support for subforms

                                                                                                                Hello everyone, We've rolled out new enhancements to the Zoho CRM Android app to bring better mobile CRM experience and efficiency. Let's take a quick look at what's new: Kiosk Multiple file uploads for subforms Kiosk Kiosk is a no-code tool in Zoho CRM
                                                                                                              • Alerts for mentions in comments

                                                                                                                We are testing the use of Writer internally and found that when a user is mentioned in a comment, there is no email alert for the mention. Is this something that's configurable, and if so, where can we enable this option?
                                                                                                              • OAuth integration issues

                                                                                                                I'm experiencing persistent OAuth errors when trying to connect Make with Zoho API. I've tried multiple approaches but keep encountering the following issues: First error: 'Invalid Redirect Uri - Redirect URI passed does not match with the one configured'
                                                                                                              • Next Page