Request.json dynamic query / Local , Prod different Results

Hello,

I’m encountering a problem when making requests to the Freshservice API from a Freshservice Serverless App. After making the request, I receive the following error response:

{

"errors": [

{

"value": "test@test.com'",

"message": "Invalid query"

}

]

}

To better diagnose the issue, I set up a Google Cloud function to fetch the Freshservice API URL generated from my app. Unfortunately, the URL received from the Google Cloud function does not match the expected Freshservice API URL format.

The expected URL format for the request should be:

/api/v2/objects/7000000250/records?query=recieving_email%20%3A%20%27helpdesk%40demo123cpl.freshservice.com%27

The relevant parts of the application responsible for making this request include the following sections from my requests.json file:

"lookdefaultbyEmail": {

"schema": {

"method": "GET",

"host": "europe-west1-cpl-mo.cloudfunctions.net",

"path": "/demo_freshservice/api/v2/objects/<%= iparam.customTableId %>/records",

"query": {

"query": "<%= iparam.customTableKey %> : <%= context.query %>"

},

"protocol": "https",

"headers": {

"Authorization": "Basic <%= encode(iparam.apiKey) %>",

"Content-Type": "application/json"

}

},

"options": {

"retryDelay": 1000

}

}

And the corresponding TypeScript function is:

export const lookdefaultbyEmail = async <V = any>(): Promise<

CustomObjectWithMetadata<V>[]

> => {

try {

const query = "'test@test.test'";

console.log({ query });

const invocation = await $extendedRequest.invokeTemplate(

"lookdefaultbyEmail",

{

context: { query },

}

);

const json = parseJson(invocation.response);

if (json?.length) return json.map((res) => res.data);

else return [];

} catch (error: any) {

console.error("An error occurred in lookupOne:", error);

throw error;

}

};

Despite many trials to adjust the code and requests.json file, I’ve been unsuccessful in achieving the correct URL format. The attempted modifications along with the resulting URLs are detailed as follows:

If

"query": {

"query": "\"<%= iparam.customTableKey %> : <%= context.query %>\""

},
const query = "'test@test.test'"; URL:

/api/v2/objects/7000000250/records?query=%22recieving_email+%3A+%26%2339%3Btest%40test.test%26%2339%3B%22"


const query = "test@test.test"; URL:

/api/v2/objects/7000000250/records?query=%22recieving_email+%3A+test%40test.test%22

"query": {

"query": "<%= iparam.customTableKey %> : <%= context.query %>"

},
const query = "'test@test.test'"; URL:

/api/v2/objects/7000000250/records?query=recieving_email+%3A+%26%2339%3Btest%40test.test%26%2339%3B

const query = "test@test.test"; URL:

/api/v2/objects/7000000250/records?query=recieving_email+%3A+test%40test.test

"query": {

"query": "<%= iparam.customTableKey %> : '<%= context.query %>'"

},

const query = "test@test.test"; URL:

/api/v2/objects/7000000250/records?query=recieving_email+%3A+‘test%40test.test’

"query": {

"query": "<%= iparam.customTableKey %> : %27<%= context.query %>%27"

},
const query = "test@test.test"; URL:

/api/v2/objects/7000000250/records?query=recieving_email+%3A+%2527test%40test.test%2527

"query": {

"query": "<%= iparam.customTableKey %> : <%= context.query %>"

},
const query = encodeURIComponent("'test@test.test'"); URL:

/api/v2/objects/7000000250/records?query=recieving_email+%3A+%26%2339%3Btest%2540test.test%26%2339%3B

“query”: {

“query”: “<%= iparam.customTableKey %><%= context.query %>”

},

const query = encodeURIComponent(" : ‘test@test.test’"); URL:


/api/v2/objects/7000000250/records?query=recieving_email%2520%253A%2520%26%2339%3Btest%2540test.test%26%2339%3B

If we decode this string we get recieving_email+:+&#39;test@test.test&#39; and finally this string is not accepted by the freshservice custom objects api endpoint.

As demonstrated above, none of these attempts have generated the desired URL format. I would appreciate your assistance in resolving this issue.

My second issue that, I'm experiencing an inconsistency in results when making requests to the Freshservice API between my local and production environments. This inconsistency makes it impossible to accurately test my app locally before moving to production.
In the test, I used the following "query" value:

“query”: {
“query”: “<%= iparam.customTableKey %> : <%= context.query %>”
},


Here are the different URLs I got in the local and production environments:

1- 

const query = “‘test@test.test’”:

-In Production: 
/api/v2/objects/7000000250/records?query=%22recieving_email+%3A+%26%2339%3Btest%40test.test%26%2339%3B%22" 
-Local: 
/api/v2/objects/7000000250/records?query=%22recieving_email%20%3A%20'test%40test.test'%22"

2- 

const query = ‘test@test.test’:

-In Production: 
/api/v2/objects/7000000250/records?query=%22recieving_email+%3A+test%40test.test%22 
-Local: 
/api/v2/objects/7000000250/records?query=%22recieving_email%20%3A%20test%40test.test%22

As shown, the local and production environments yield different results for the same query, which is causing issues for testing. I would appreciate any assistance you can provide in understanding and resolving this discrepancy.

Hello, @Mo_Ay,

Thank you for providing the details. Kindly grant us a couple of days to prioritize and investigate this matter. Initially, it appears that the issue pertains to how we are managing query parameters and their encoding.

Hi,

I’d just like to add that I am having issues around a similar API request, attempting to query Custom Objects records using postman.

The syntax looks correct to me:

https://xxxxxxx.freshservice.com/api/v2/objects/75000007590/records?query="bo_display_id:202"

But I receive the following response:

{"errors":[{"name":"\"bo_display_id:202\"","message":"Invalid query"}]}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.