Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hy everyone,
I'm trying to do a REST connection through POST method to read a XML document, but I'm failling.
I created the connection with the webservice using the QlikRESTConnector, passing the URL, method as post, user, password and the name of the connection. All the other settings was black or already filled as defaults values.
Then I created the following code:
Let vRequestBody ='';
let vRequestBody = vRequestBody &'<?xml version="1.0" encoding="utf-8" ?>';
let vRequestBody = vRequestBody &'<xDBCompanyNamex>';
let vRequestBody = vRequestBody &'<Authentication user="xUserx" password="xPasswordx" />';
let vRequestBody = vRequestBody &'<ResponseFormat>xml</ResponseFormat>';
let vRequestBody = vRequestBody &'<Command><Name>xWebServiceMethodNamex</Name>';
let vRequestBody = vRequestBody &'<Parameters>';
let vRequestBody = vRequestBody &'<Parameter id="xParameter1x">xKEYx</Parameter>';
let vRequestBody = vRequestBody &'<Parameter id="xParameter2x">xNamex</Parameter>';
let vRequestBody = vRequestBody &'</Parameters>';
let vRequestBody = vRequestBody &'</Command>';
let vRequestBody = vRequestBody &'</xDBCompanyNamex>';
let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34));
So, the string connection is:
<?xml version=""1.0"" encoding=""utf-8"" ?>
<xDBCompanyNamex>
<Authentication user=""xUserx"" password=""xPasswordx"" />
<ResponseFormat>xml</ResponseFormat>
<Command><Name>xWebServiceMethodNamex</Name>
<Parameters>
<Parameter id=""xParameter1x"">xKEYx</Parameter>
<Parameter id=""xParameter2x"">xNamex</Parameter>
</Parameters>
</Command>
</xDBCompanyNamex>
This two quotation marks is weirdo to me, but the code that was working before have it and I just copied.
I run the code above with one quotation mark in the GetPostman and I achieve the expected outcome, so I tried the code with just one quotation mark on Qlik too, but the result is the same:
Root element is missing.
Any ideas about how to resolve that?
Thanks and sorry for the English.
Gabriela,
You'll have to paste the baseline (non-variable) Request body in your Connection definition so it can find the XML to pull.
<?xml version=""1.0"" encoding=""utf-8"" ?>
<xDBCompanyNamex>
<Authentication user=""xUserx"" password=""xPasswordx"" />
<ResponseFormat>xml</ResponseFormat>
<Command><Name>xWebServiceMethodNamex</Name>
<Parameters>
<Parameter id=""xParameter1x"">xKEYx</Parameter>
<Parameter id=""xParameter2x"">xNamex</Parameter>
</Parameters>
</Command>
</xDBCompanyNamex>
If it works correctly, you should see the button identified below.
If so, click it, it will insert the library connect to statement and pop up a dialog which allows you to select the data elements to include. I've found that this screen is buggy with 3.2, so you may have some UI issues where it doesn't look right. If that is the case, select the table in the left column, check the box in one of the columns on the right, and then check the box next to the table to select all columns. I've found this necessary to get around the bug.
This will insert t he select which you can then modify with the WITH CONNECT keyword and your dynamically defined variable as previously discussed.
Hope this helps.
Chance
Gabriela,
Can you post the resulting rest connection string so I can understand how you are using it with the vRequestBody variable?
Hello Chance,
I don't have this string. At least I don't know to get it in Qlik Sense.
I just clik in this button to do the connection.
Does the request body need to be dynamic or can you include it in the 'Request Body' section when you create the REST connection with the POST method?
If you need to make the request body dynamic, consider setting it up with static text and then using the WITH CONNECTION keyword as documented on Qlik Help.
This will enable you to build out your dynamic request body and override the original as needed.
Hope this helps.
Chance
Hi Chance,
I saw this document before, but the problem is that I don't know how to generate the SELECT to put the variable.
Some people told me that just creating this variable, when I click in that button that I show you in the last post, it's already create the connection. Looks like doesn't work this way, so now I have to create the SELECT, but I don't know how.
I achieve the results in QlikView and in QlikSense
But I'm still trying to do it dynamic in QlikSense.
I tryed to do this way, but it's not working.
Gabriela,
You'll have to paste the baseline (non-variable) Request body in your Connection definition so it can find the XML to pull.
<?xml version=""1.0"" encoding=""utf-8"" ?>
<xDBCompanyNamex>
<Authentication user=""xUserx"" password=""xPasswordx"" />
<ResponseFormat>xml</ResponseFormat>
<Command><Name>xWebServiceMethodNamex</Name>
<Parameters>
<Parameter id=""xParameter1x"">xKEYx</Parameter>
<Parameter id=""xParameter2x"">xNamex</Parameter>
</Parameters>
</Command>
</xDBCompanyNamex>
If it works correctly, you should see the button identified below.
If so, click it, it will insert the library connect to statement and pop up a dialog which allows you to select the data elements to include. I've found that this screen is buggy with 3.2, so you may have some UI issues where it doesn't look right. If that is the case, select the table in the left column, check the box in one of the columns on the right, and then check the box next to the table to select all columns. I've found this necessary to get around the bug.
This will insert t he select which you can then modify with the WITH CONNECT keyword and your dynamically defined variable as previously discussed.
Hope this helps.
Chance
Hi Gabriela,
I am trying to do what you have suggested above. I just need to replace a Enddate which is in my POST content
"dateEnd": "2016-04-01T08:50:53.082Z"
I found on other ticket this is how to do it :
let vRequestBody = '{"dateEnd": "2016-04-01T08:50:53.082Z"}';
let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34));
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(
BODY "$(vRequestBody)"
)
;
I can replace 2016-04-01 by any variable but problem is where I am executing it it is returning error:
Connector reply error: Unknown substring, string, or value at (50,23): '-04-01T08:50:53.082Z"}"'
Can you please help me to fix it
Best.
Rohit
Hi,
Is it possible to create Rest connection without credential in Qliksense? I can only create after providing my windows credential.But if some other want to access it I think he cant.