Hi,
I encountered some issues to create estimates or invoices because they keep being registered as 'draft',
whereas my parameters aren't for drafts.
I use Apps Script to make my requests.
Here the code to create an estimate with 'sent' status but I still get a draft :
- var json = {
- "customer_id": clientIdZoho,
- "template_id": templateZohoIdDevis,
- "name": zohoItem.name,
- "date": dateDevisCreation,
- "expiry_date": dateDevisFin,
- "line_items": [{
- "item_id": zohoItem.item_id,
- "description" : description,
- "rate":prix,
- "quantity": quantite,
- "tax_id": zohoItem.tax_id,
- "tax_name": zohoItem.tax_name,
- "tax_percentage": zohoItem.tax_name
- }]
- ,
- "status": "sent",
- "send" : true,
- };
- }
- var options = {
- 'method': 'POST',
- 'headers' : {
- 'Authorization': 'Zoho-oauthtoken '+accessToken,
- 'X-com-zoho-invoice-organizationid': ORGANIZATION_ID_V2,
- 'Content-Type' : 'application/json'
- },
- 'payload' : JSON.stringify(json),
- 'muteHttpExceptions' : true
- }
- var resultat = UrlFetchApp.fetch(url,options);
I decided to change my plan and to use the request given by the api to change its state after being created.
However, I keep getting the error code : 2, "The request passed is not valid." . I tried with ARC (similar to postman) and it worked with the same parameters, but still not in my code.
Here my code :
- function setDevisAsSend(idDevis){
- var idDevis = "--------";//JSON.parse(resultat.getContentText()).estimate.estimate_id;
- var accessToken =getZohoAccessToken();
- var url='https://invoice.zoho.com/api/v3/estimates/'+idDevis+'/status/sent?X-com-zoho-invoice-organizationid=-----';
- var options = {
- 'method': 'POST',
- 'headers' : {
- 'Authorization': 'Zoho-oauthtoken '+accessToken,
- 'Content-Type' : 'multipart/form-data'
- },
- 'muteHttpExceptions' : true
- }
- Logger.log(url);
- Logger.log(options);
- var response = UrlFetchApp.fetch(url, options);
- Logger.log(response);
- }
I already use the same syntax for other resquests and it works, my scope is correct and
the access token is valid too.
I would really appreciate any help !
Here an exemple of an other request working well :
- var accessToken =getZohoAccessToken();
- var url='https://invoice.zoho.com/api/v3/contacts';
- var options = {
- 'headers' : {
- 'Authorization': 'Zoho-oauthtoken '+accessToken,
- 'X-com-zoho-invoice-organizationid': ORGANIZATION_ID_V2,
- 'Content-Type' : 'multipart/form-data'
- },
- 'muteHttpExceptions' : true
- }
- var response = UrlFetchApp.fetch(url, options);