Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
The webservice expecting a JSON with parameters in the body
But I need the body to be dynamically changed according to the user selection,
something like the pic attached (the connector works when the body is hardcoded)
will appreciate any help or guidance on that
thanks
Eran
Hi @EranRaz
You will want to look at the WITH CONNECTION property of the connection:
Whether or not you will be able to pass in a whole chunk of JSON like that or not I am not sure, but this is definitely the approach to try first.
If not a JSON block you may be able to specify each of the parts as separate parameters?
Hope that helps.
Steve
Hi @EranRaz
The WITH CONNECTION requires double quotes to be used around the body, which then means that these can't (I imagine) be used in the body that is sent.
I guess that if you remove all of the double quotes from the body it will not work?
Steve
The browser (or proxy) sent a request that this server could not understand.
Hi @EranRaz
Have you tried without double quotes or the square brackets? None of the parameter names and values have spaces, so this may work.
It may be that passing a BODY tag in like that will not work.
Can you try setting up each of the values as a parameter, first in a connection using the dialog and then if that works replacing it with WITH CONNECTION, listing each parameter separately.
Steve
Tagging @chrisbrain as he may have some thoughts. I would have thought this is quite a common requirement/problem.
Hi @EranRaz / @stevedark ,
I think I may have this working. I created a connection to this test service:
https://jsonplaceholder.typicode.com/posts
(From https://jsonplaceholder.typicode.com/guide/)
Using:
{
"title": "foo",
"body": "bar",
"userId": 1
}
I then made a selection from the connection and updated the script to the following, which seems to work:
let vTitle = 'Test title';
let vBody = 'Test body';
let vId = 456;
RestConnectorMasterTable:
SQL SELECT
"title",
"body",
"userId",
"id"
FROM JSON (wrap on) "root"
WITH CONNECTION(BODY "{
""title"": ""$(vTitle)"",
""body"": ""$(vBody)"",
""userId"": $(vId)
}");
[root]:
LOAD [title],
[body],
[userId],
[id]
RESIDENT RestConnectorMasterTable;
DROP TABLE RestConnectorMasterTable;
The trick here was to use double doublequotes inside the single double quotes - this is actually in the docs at:
https://help.qlik.com/en-US/sense/November2020/Subsystems/Hub/Content/Sense_Hub/Scripting/use-quotes...
(The 'Use escape characters' section at the end).
Hopefully this is close to what you need and you can adapt it.