Request.json dynamic query

Hello guys, I’m making the following request:

  "fileterContacts": {
    "schema": {
      "method": "GET",
      "host": "<%= iparam.domainName %>.freshdesk.com",
      "path": "/api/v2/contacts",
      "headers": {
        "Authorization": "Basic <%= encode(iparam.apiKey) %>",
        "Content-Type": "application/json"
      },
      "query": {
        "email": "<%= context.email %>",
        "mobile": "<%= context.phone %>"
      }
    }
  },

But my query is dynamic, I can pass only email or just phone, or both together, in this example it filters by passing phone as empty if I do not pass anything, which compromises the query, so I need to somehow solve this problem, example if the parameter is null or something like it should not be sent!

I don’t think it’s a good solution to create 3 requests that do the same thing just because of parameters of a query

I had a similar requirement.

I’m glad I’m not alone. I don’t see any reason why query params need to be part of the template in the first place. It does not pose a security threat in any way. It only makes the request template unnecessarily rigid.

The way I worked around it was to construct the query params as part of the path itself.

"path": "/api/v2/contacts?email=xxx&mobile=yyy",
4 Likes

Hey guys, can you give us a feedback?

@Saif @Raviraj

1 Like

Let me tag @zach_jones_noel to take up this feedback. He is working on a similar case collecting feedback for potential duplication of request templates increasing the total count.

1 Like

Hey @Marllon_Mainardes,

Thanks for bringing this to our notice!

Currently, if you are using the query parameters in request template then it’s hard bound to create 3 different templates based on your use-case here -

"query": {
        "email": "<%= context.email %>",
        "mobile": "<%= context.phone %>"
      }
"query": {
        "email": "<%= context.email %>"
      }
"query": {
        "mobile": "<%= context.phone %>"
      }

Like @arunrajkumar235 mentioned, using query parameters in the path and setting them via context variable would be a better approach in this specific use case.

"path": "/api/v2/contacts<%= context.queryparams %>

And while invoking, dynamically set the queryparams to hold either ?email=xxx&&mobile=yyy or ?email=xxx or ?mobile=yyy

1 Like

@zach_jones_noel @arunrajkumar235 are you guys sure that using query params in the path works in production?

Running the app locally it works, but when published, my server receives the query like this:

?email=xxx&amp;mobile=yyy

and decodes to:

{
  email: 'xxx',
  'amp;mobile': 'yyy'
}

&amp; is for encoding the ampersand in HTML

Should it not come just as & ?

Hey @samuelpares,
Agree that it should be ?email=xxx&mobile=yyy.

Can you share the requests.json and also your App details?

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