This is slightly different to my article Zoho Deluge: Get Refresh/Access Token API v2 (Zoho to Zoho service) and different to my Zoho CRM: APIv2 using PHP & cURL (3rd-Party to Zoho), in that this details how to setup a connection to use in an invoke URL statement. Specifically for Zoho Books, Subscriptions or Inventory.
Why?
Setting up a connection avoids the hassle of having to generate access/refresh tokens using OAuth2.0. Usually used with an invokeUrl:
response = invokeUrl [ url: "https://books.zoho.com/api/v3/estimates?organization_id=12346789" type: GET connection: "joelconnector" ];
- response = invokeUrl
- [
- url: "https://books.zoho.com/api/v3/estimates?organization_id=12346789"
- type: GET
- connection: "joelconnector"
- ];
How?
So in the following example, we are going to setup a connection in Zoho Books on an EU datacenter:
- First determine what datacenter your client is using
- Register the App
- Setup the Connector
How do I determine what datacenter to use?
To find out which datacenter your client/customer is using in Zoho, check the domain and specifically the top-level-domain (TLD) part. For example, if it says zoho.com, then this means the US datacenter. If it says zoho.eu, then this is the EU datacenter. If it says zoho.in, then this is the India datacenter.
View the attached if this is still confusing. The following screenshot is of a client's Zoho Books instance opened in a browser. the circled part is the domain of the Zoho app we are accessing:
Here is a list of the datacenters that I know of:
- AU = Australia (zoho.com.au)
- CN = China (zoho.com.cn)
- EU = Europe (zoho.eu)
- IN = India (zoho.in)
- US = United States (zoho.com)
Registering the App
You need to do this so as to tell which Zoho system for which organization you are connecting to. If you get this wrong, you may access the wrong system (such as your own rather than the clients) or you may not access anything at all.
- Open a new browser window (preferably using the Google Chrome profile you have for the customer) Logged in to Zoho as an Administrator of the system to access.
- Browse to the Zoho Developer Console at the appropriate link based on the clients datacenter:
- US datacenter: https://api-console.zoho.com/
- EU datacenter: https://api-console.zoho.eu/
- If this is your first app, then click on "Get Started" and select "Server-based Applications" by clicking on "Create Now" on the appropriate box.
- If this is not your first app, just select "Server-based Applications", then on the plus icon to add new client.
- Fill in the new form to Create New Client:
- Client Name: put something descriptive so it is easy to identify if the client has 3rd-parties adding clients. eg. "JoelLipman_BooksConnector".
- Homepage URL: put our corporate website URL, this is for developers who need to query what this app belongs to or does. eg. "https://www.joellipman.com/"
- Authorized Redirect URIs: for this put in one of the following options, again, based on the clients datacenter:
- US datacenter: https://deluge.zoho.com/delugeauth/callback
- EU datacenter: https://dre.zoho.eu/delugeauth/callback
- CN datacenter: https://dre.zoho.com.cn/delugeauth/callback
- IN datacenter: https://dre.zoho.in/delugeauth/callback
- Click on "Create"
- You will be issued a Client ID and Client Secret, make a note of these or leave this window to copy&paste into the next step.
Setting up the Oauth Connector
So return to your Zoho Books instance (or Subscriptions, Inventory, app you were making the connection):- From within books (or inventory, subscriptions as these are simillar), go to edit a custom function and click on the "Connections" link to the top right of a function:
- If this is your first connection, simply click on the "Go To Connections" button
- Select "Custom Service" and complete the form:
- Service Name: Enter a descriptive name that can help you find it amongst many connections. eg. "the Joel Lipman App".
- Service LinkName: Not sure what this is used for but I enter the same name in lowercase and replacing special characters with an underscore. eg. "the_joel_lipman_app"
- Authentication Type: set this to "oauth2"
- Param Type: set this to "Header"
- Grant Type: set this to "Authorization Code"
- Client ID: Copy & paste from the previous step this value into this field.
- Client Secret: Copy & paste from the previous step this value into this field.
- Authorize URL: Enter the Zoho authentication URL based on the client's datacenter:
- US datacenter: https://accounts.zoho.com/oauth/v2/auth
- EU datacenter: https://accounts.zoho.eu/oauth/v2/auth
- CN datacenter: https://accounts.zoho.com.cn/oauth/v2/auth
- IN datacenter: https://accounts.zoho.in/oauth/v2/auth
- Access Token URL: Enter the Zoho token URL based on the client's datacenter:
- US datacenter: https://accounts.zoho.com/oauth/v2/token
- EU datacenter: https://accounts.zoho.eu/oauth/v2/token
- CN datacenter: https://accounts.zoho.com.cn/oauth/v2/token
- IN datacenter: https://accounts.zoho.in/oauth/v2/token
- Refresh Token URL: Enter the Zoho token URL based on the client's datacenter:
- US datacenter: https://accounts.zoho.com/oauth/v2/token
- EU datacenter: https://accounts.zoho.eu/oauth/v2/token
- CN datacenter: https://accounts.zoho.com.cn/oauth/v2/token
- IN datacenter: https://accounts.zoho.in/oauth/v2/token
- Connection Name: Put a descriptive name
- Connection LinkName: Put the link name that we will use in code later (preferably in lowercase as it will lowercase it anyway)
- Scope: Enter each scope you need and click on the plus icon to add each one.
- Keep "Use credentials of login user" ticked.
- You should have something like the following:
- Click on "Create and Connect"
- You will get a popup confirming what this app will access and you should click on "Accept":
- A quick popup will appear to say connected. Done!
Now you can use this in your custom function with the invokeURL without the need for a header parameter:copyrawresponse = invokeUrl [ url: "https://books.zoho.com/api/v3/estimates?organization_id=12346789" type: GET connection: "joelconnector" ];
- response = invokeUrl
- [
- url: "https://books.zoho.com/api/v3/estimates?organization_id=12346789"
- type: GET
- connection: "joelconnector"
- ];
Additional
I'd always recommend locking down your app privileges by checking the scope(s) you have allowed it to have.... However in those times of debugging/testing when you can't seem to access that bit of information Zoho is reluctantly letting you have (such as comment information for estimates/sales orders/invoices). There are some quietly documented scopes granting absolute access:- ZohoBooks.fullaccess.all
- ZohoInventory.FullAccess.all
- ZohoSubscriptions.fullaccess.all
Other Links- Zoho Documentation: Connections
- Zoho Documentation: Books API v3
- Zoho Documentation: CRM API v2
- Zoho Documentation: Subscriptions API v1
Category: Zoho :: Article: 728