josh_mam
josh_mam

Reputation: 29

How to include json as a query parameter in Zapier app

I am trying to create a Zapier app to create a new invoice in Zoho.

Has the requirements: Content-Type: application: x-www-form-urlencoded and input JSON string should be passed using JSONString parameter

The following URI is working for me in REST console when I set the Content Type to "application/x-www-form-urlencoded" and method POST.

https://invoice.zoho.com/api/v3/invoices?authtoken=xxxxxx&organization_id=xxxxxx&JSONString={"customer_id":"xxxxxx","line_items":[{"item_id":"xxxxxx"}]}

However my problem is trying to implement this into Zapier. I think I need to use a function like below to convert the JSON into the right format, but I have no idea how to turn this into a query paramater called JSONString.

create_invoice_pre_write: function(bundle) {
    var data = JSON.parse(bundle.request.data);
    bundle.request.data = $.param(data);
    bundle.request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    return bundle.request;
}   

Just need a point in the right direction. I'm not sure what to try next.

Upvotes: 0

Views: 482

Answers (1)

Anjali Mohanraj
Anjali Mohanraj

Reputation: 21

You can create an Invoice in Zoho Invoice through Zapier using the below snippet of code.

You can set the query params in bundle.request.params which you want to send it to ZI for the creation of Invoice.

create_invoice_pre_write: function(bundle)
{ 
 var data = JSON.parse(bundle.request.data);
 bundle.request.method = "POST",
 bundle.request.url = "https://invoice.zoho.com/api/v3/invoices",
 bundle.request.params.authtoken = {authtoken},
 bundle.request.params.organization_id = {organization_id},
 bundle.request.params.JSONString = data
 bundle.request.headers= "'Content-Type':'application/x-www-form-urlencoded'";
    return bundle.request;
}

This should be working for you. If you have any doubts do let me know.

Upvotes: 2

Related Questions