Hi team,
I am raising this on behalf of our customer, Tatadigital, from the IND region. They are currently developing an app using our SDK, using API to fetch tickets filtered by status and a custom field value. The code details can be found below.
Domain Name - tatadigitalsit.com
server.js
async function bulkticketResolve(resolveBy, currentMinusOneHrs) {
console.log(“Inside bulkticketResolve Fn”, resolveBy);
console.log(currentMinusOneHrs,‘currentMinusOneHrscurrentMinusOneHrs’);
try {
filter = “status:18”;
var searchTkt = await fd.searchTickets(filter);
console.log(‘after api call searchTickets’);
var searchTktRes = JSON.parse(searchTkt.response);
console.log(JSON.stringify(searchTktRes));
const result = searchTktRes.filter(item =>
item.status == 18
)
const filteredResult = result.map(obj => (
id = obj.id
))
console.log(“filteredResult”);
console.log(JSON.stringify(filteredResult));
} catch (e) {
console.log(‘error inside catch’);
console.log(e);
return false;
}
fd-api-server.js
searchTickets: function (query) {
// /api/v2/search/tickets?query="status:18"
var url = '/api/v2/search/tickets?query="status:18"';
console.log(query )
console.log(url , 'urllllllllll');
return $request.invokeTemplate("getFDapi", {
"context": {
"url": url
},
});
}
The API seems to fetch the expected results in Postman but when used as a part of the code in the app, this led to the following error.
{
status: 400,
headers: {},
response: ‘error while substituting templates.’,
errors: {},
errorSource: ‘APP’,
attempts: 1
}
Can we please check if the code needs to be changed to fix this?
Anish
December 26, 2024, 3:59am
2
Hi @Vijay_Kannan ,
Greetings!
Thank you for reaching out to the community.
Have you tried making the same request in Postman? It seems there might be an issue with how the data is being passed.
Could you please share your requests.json file for further review?
Thanks,
Anish
This happens when one or more of the variable required for requestTemplate isn’t passed. Please share the requests.json so we can find out what is being missed.
Raviraj
(Raviraj Subramanian)
December 26, 2024, 5:40am
4
As @sureshprasanna pointed, the template used for making API request might be missing or wrong syntax. Filter API requires the filter params to be URL encoded. It should be URL encoded before using it in the request. Postman will automatically do.
So, could you share the request template used so that we can point out what might be wrong?
Also, could you enter the entire URL along with query params URL encoded passed in the Path in the request template and make it work? After it works, then whatever needs to be passed dynamically can be passed from iparams and context templates.
Some solutions available in the community:
With help from @zach_jones_noel and @Nadeem_Bhati I found the solution to this. It works if you add escaped double quotes either side of the context placeholder in the request template.
Shout out to @Ansfs91 who suggested the same solution but I missed that he had manually added encoded double quotes to the request template path in his solution when I tried, so thought it didn’t work. Apologies Albin.
NOTE: If you send the query string in the context object from the code with double quotes, e…
Hi team,
The customer provided request.json for further analysis. Please let us know your thoughts on this.
Resuest .json
{
“verifyFDCredentials”: {
“schema”: {
“protocol”: “https”,
“host”: “<%= context.host%>”,
“path”: “/api/v2/ticket_fields”,
“method”: “GET”,
“headers”: {
“Authorization”: “Basic <%= context.api_key%>”
}
}
},
“postCredentials”: {
“schema”: {
“protocol”: “https”,
“host”: “<%= iparam.tdlDomain %>”,
“path”: “<%= context.url %>”,
“method”: “POST”,
“headers”: {
“client_id” : “<%= iparam.clientId %>”,
“Authorization” : “<%= iparam.tdlApiKey %>”,
“Content-Type” : “text/plain”
}
}
},
“postFDapi”: {
“schema”: {
“protocol”: “https”,
“host”: “<%= iparam.domain %>”,
“path”: “<%= context.url %>”,
“method”: “POST”,
“headers”: {
“Authorization”: “Basic <%= encode(iparam.apiKey + ‘:X’) %>”,
“Content-Type”: “application/json”
}
}
},
“putFDapi”: {
“schema”: {
“protocol”: “https”,
“host”: “<%= iparam.domain %>”,
“path”: “<%= context.url %>”,
“method”: “PUT”,
“headers”: {
“Authorization”: “Basic <%= encode(iparam.apiKey + ‘:X’) %>”,
“Content-Type”: “application/json”
}
}
},
“getFDapi”: {
“schema”: {
“protocol”: “https”,
“host”: “<%= iparam.domain %>”,
“path”: “<%= context.url %>”,
“method”: “GET”,
“headers”: {
“Authorization”: “Basic <%= encode(iparam.apiKey + ‘:X’) %>”,
“Content-Type”: “application/json”
}
}
},
“gettier”: {
“schema”: {
“protocol”: “https”,
“host”: “<%= iparam.tdlDomain %>”,
“path”: “<%= context.url %>”,
“method”: “GET”,
“headers”: {
“client_id” : “CS-WEB-APP”,
“Authorization” : “<%= iparam.tdlApiKey %>”,
“Content-Type”: “application/json”,
“store_id”: “sit.tcp.online”,
“customerHash”: “<%= context.custHash %>”
}
}
}
}
Hi @Vijay_Kannan ,
Greetings!
Try without the X
"Basic <%= encode(iparam.apiKey) %>"
This should fix the issue.
Hope that helps, let me otherwise.
Thank you.
The encode, does the btoa internally so you can use it without the :X.