Zoho Books API – Google Sheets

I am recording my sales details in Google Sheets and am using Zoho Books to maintain my books of accounts. I want to use Zoho Books API to sync data between google sheets and Zoho Books. I have done the following till now:

  1. Created a Self-Client in Zoho API Console to generate a Client ID and Client Secret
  2. Generated an authorization code for all Scopes under Invoices in the Zoho API Console
  3. Generated an access token and refresh token - using Postman
  4. Wrote the following code in Google Apps Script to create an invoice with dummy data
function ZohoInvoice() {
  var invoice = {
    customer_id: '2298656000000277003',
    invoice_number: 'MU001',
    date: '2021-09-02',
    line_items: [
      {
        item_id: '2298656000002380000',
        name: 'Item1',
        description: 'This is the description',
        rate: '1500.00',
        quantity: '2',
      },
    ],
    notes: 'These are the notes of this Invocie'
  };

  var zohoOauthToken = '1000.827612479824c7c66132118bb242e15942aa6a.4e63c9fd60a343658904a54191c4c32';
  var zohoOrganization = '19012342064';

  var zohoUrl = [
    'https://books.zoho.com/api/v3/invoices?',
    'organization_id=',
    zohoOrganization,
    '&authtoken=',
    zohoOauthToken,
    '&JSONString=',
    encodeURIComponent(JSON.stringify(invoice)),
  ].join('');

  try {
    var response = UrlFetchApp.fetch(zohoUrl, {
      method: 'POST',
      muteHttpExceptions: true,
    });
    var result = JSON.parse(response.getContentText());
    Logger.log(result.message);
  } catch (error) {
    Logger.log(error.toString());
  }
}

The above code throws an error Invalid value passed for authtoken.

Unsure where am I going wrong?



Read more here: https://stackoverflow.com/questions/67396500/zoho-books-api-google-sheets

Content Attribution

This content was originally published by Mohit Baid at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: