Tim C
Tim C5mo ago

Tim C - I'm trying to refactor an inbound query...

I'm trying to refactor an inbound query that I have no control over. It takes the form of https://target/api#param=value&param2=value. I want to refactor this to https://target/api?param=value&param2=value. I feel like this is trivially easy, but I'm stuck extracting the calling URL. If have an API GET trigger at the beginning of my workflow, then I try to access the calling URL in a subsequent node with Query.url, but I get an error that the URL is invalid, and the object I see in the logs doesn't appear to have anything containing the original query. Any way to access the full original query that triggered the workflow?
5 Replies
Gaurav Chadha
Gaurav Chadha5mo ago
Hi @Tim C, there are couple of ways to access the query. 1. Adding the Query keys in the REST API Trigger. link 2. Using the API Call node.link For the above case I suggest using the API Call node to make a request to the desired endpoint https://target/api?param=value&param2=value endpoint, you can also add as many query parameters in the endpoint or either separately like this:
{
"query1": "value1",
"query2": "value2"
}
{
"query1": "value1",
"query2": "value2"
}
Note; the above method only works for making a call to this type of url - https://target/api?param=value&param2=value.
REST API Query Param
No description
Gaurav Chadha
Gaurav Chadha5mo ago
To convert the you can use the basic JS operations eg: slice(), or leverage the AI node generator to create a node to convert it. Here's one you can use, you can copy this and paste it to a new node (from the node explorer).
Tim C
Tim C5mo ago
Thanks @Gaurav Chadha, appreciate the assist. I probably didn't explain my problem well enough, though. I have no issues converting the inbound URL from using fragments to regular parameters and then passing that on. The issue is getting access to the inbound trigger API call. The entire flow is: 1. app1 calls my buildship API with https://buildship/api#param1=value1&param2=value2 2. buildship receives this call, applies logic to swap the # for ? 3. buildship calls my downstream app with https://otherapp/api?param1=value1&param2=value2 The issue is capturing the URL in step 1... I try to reference Query.url in step 2, but this returns the attached error. NB: I stripped out all the logic to confirm I hadn't done something else silly and instead just reference the value directly... I realise I actually need to do something with the url once I find it.
No description
Gaurav Chadha
Gaurav Chadha5mo ago
Thanks for explaining further, directly calling any URL with # is not supported, if you are sending the URL as query (as seen in the image) then it will be easy to capture it and do manipulation, use the Get query param node and send the URL as query.
No description
Tim C
Tim C5mo ago
Thanks again @Gaurav Chadha. Unfortunately I have no control over the inbound query (step 1). I can only change the endpoint. That's the reason why I'm doing this in the first place... the query-as-a-fragment approach of this request also doesn't work with the app I want to ultimately receive the request, so I thought to use Buildship to translate it. Step 1 will always take the form https://host/endpoint#param=value. From what you're saying though, it's not possible to capture this, even as text, using Buidlship. Is that right?