I am trying to access a capsule CRM API (documentation here)
I am quite new to google app script and was trying to convert a curl request into a gas function using UrlFetchApp
I am trying to search for a certain party via the API -- they provide this endpoint:
GET
https://api.capsulecrm.com/api/v2/parties/search
These are the Search parameters in the request:
- q _________Type(String)___:The value to search for e.g. a name
- page______Type(Integer)__:The page of results to return
- perPage___Type(Integer)__:Number of entities to return per page
Their API Documentation says that you would read data from the API by doing the following:
curl -H "Authorization: Bearer {token}"
-H "Accept: application/json"
https://api.capsulecrm.com/api/v2/parties
The following is my gas function which does return the data, but does not effectively search for the correct record and return only the resultset. I would like to know if there is an easier and better way to perform this search?
function curlRequest(partyid) {
var authenticationToken = "XvDEdg652DG...xYYRg";
//var url = "https://api.capsulecrm.com/api/v2/parties";
var url = "https://api.capsulecrm.com/api/v2/parties/search";
var headers = {
"Authorization" : "Bearer " + authenticationToken,
};
var payload = {
"Accept": "application/json",
"q":{
"id":101756643
},
"page":1,
"perPage": 50,
};
var options = {
"headers" : headers,
"method" : "GET"
};
Logger.log(options);
Logger.log(UrlFetchApp.fetch(url, options));
//var data = JSON.parse(response.getContentText());
}
EDIT: based on feedback from Jack Brown:
It seems that the advice is correct, however the Capsule API is not geared for this structure:
