Connecting google apps script and Zoho Books API

Connecting google apps script and Zoho Books API

Hi all, I'm encountering an issue with no real clarity on what the exact cause is.

My goal is to connect google sheets to our Zoho Books API to generate new customer payments based on data imported to a google sheet.

So far I've been successful in looking up our customer's using the "get contact" call
(https://www.zoho.com/books/api/v3/#Contacts_Get_Contact),
as well as obtaining a customer's invoices using the "list invoices" call
(https://www.zoho.com/books/api/v3/#Invoices_List_invoices).

So I'm confident that my variables for my org ID and auth are both correct. I'm also certain the customer_id's I'm passing in are correct, as they're being properly used to gather invoices and balances and all of those match up 100%.

Here is the function I'm using to pass in my "payment" object to the "create payment" call.
  1. function postPayments(tx){
    for (let i = 1; i < tx.length; i++){
    if (tx[i]["Payment"]);
    let payment = tx[i]["Payment"];
    Logger.log(payment);
    let payload = {
    "JSONString": JSON.stringify(payment)
    }
    Logger.log(payload);
    let options = {
    "method": "POST",
    "payload": payload,
    "muteHttpExceptions": true
    }
    let zohoPaymentsURL = `https://books.zoho.com/api/v3/customerpayments?authtoken=${zohoAuthToken}&organization_id=${zohoOrgID}`;
    let responseJSON = UrlFetchApp.fetch(url=zohoPaymentsURL, params=options)
    Logger.log(responseJSON);
    let response = JSON.parse(responseJSON);
    Logger.log(response);
    }
    }
Now, this is in google scripts, which is like a modified javascript. So if anything looks odd, it may just be specific to google scripts.

Here's what the payload looks like:
  1. {JSONString={"customer_id":"1626010000005422860","payment_mode":"creditcard","amount":50,"date":"2021-02-22","reference_number":"89450082","invoices":[{"invoice_id":"1604694","amount_applied":48.71},{"invoice_id":"1712838","amount_applied":1.29}],"account_id":"1626010000001224003"}}
Here's what the response looks like:
  1. {"code":3004,"message":"The Customer field can neither be blank nor be incorrect. Please enter a correct customer."}
I've also tried passing the customer ID in the url, which yields the same result.

The response leads me to believe there is some unlisted field called "Customer" that matters, somehow, or that the response isn't detailed enough to really determine what the exact issue is.

If anyone else has resolved something similar I would love to know what you did, or what you might think the issue is.