Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Authentication >

Xero Google Scripts Authentication with parameters

Started by Danyal Khan -   in API Authentication

I am using a google script to get a profit and loss report and I am able to get the report with the oauth authentication using this as the url:
https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss

However, when I add a parameter like:
https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=2018-03-01

The response that I get is:
oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20signature


Can anyone please help with this.
Best Reply as chosen by Danyal Khan (Original Poster)
Just in case someone comes back here.

The solution that worked for me is to encode the parameter in the signature base:

var signatureBase = "GET" + "&" + encodeURIComponent(URL) + "&" + encodeURIComponent("oauth_consumer_key=" + CONSUMER_KEY + "&oauth_nonce=" + oauth_nonce + "&oauth_signature_method=RSA-SHA1&oauth_timestamp=" + oauth_timestamp + "&oauth_token=" + CONSUMER_KEY + "&oauth_version=1.0" + '&trackingCategoryID=abc123&trackingOptionID=123abc');

And also add it to the fetch url:

UrlFetchApp.fetch(URL + '?trackingCategoryID=abc123&trackingOptionID=123abc', options);

This should work for other parameters as well.
 

Danyal Khan