I am working with the leagacy xml-rpc API of InfusionSoft to just update a few contact details of a contact like email and opt-out reason etc.
I am using google apps script to achieve that as the data with contact-id is available there as a list. Though, it is part of a larger project where these contacts are being retrieved from other sources.
I often see that I get a response 401 (Not Authorized) message in response to the requests being made. It requires regenerating the access token to get those requests through.
Is there any way, to have never-expiring token or some maximum time limit for that? as the client needs to regenerate token often to get that data updated.
The script needs to run daily for all new contacts available on the list, and no other direct user activity is involved.
I am sharing the sample code, retrieving contact details and that works fine when new token is generated the same day.
function infusionTry()
{
var KEY = APIKEY;
var INF_TOKEN = ACCESS_TOKEN;
var url = "https://api.infusionsoft.com/crm/xmlrpc/v1?access_token=" + INF_TOKEN;
var payload = HtmlService.createTemplateFromFile("ReqData").getRawContent();
payload = payload.replace("{privateKey}",KEY);
payload = payload.replace("{contactIDNumber}",666486);
var params = {
method: "post",
contentType : "application/xml",
payload : payload,
muteHttpExceptions: true
};
var resp = UrlFetchApp.fetch(url, params);
Logger.log(resp.getResponseCode());
Logger.log(resp.getContentText());
}
Thanks.