Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

REST connection POST method - QlikSense

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.

1 Solution

Accepted Solutions
chancekbarkley
Partner - Contributor III
Partner - Contributor III

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. 

2017-03-16_10-54-39.png

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

View solution in original post

9 Replies
chancekbarkley
Partner - Contributor III
Partner - Contributor III

Gabriela,

Can you post the resulting rest connection string so I can understand how you are using it with the vRequestBody variable?

Not applicable
Author

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.

chancekbarkley
Partner - Contributor III
Partner - Contributor III

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

Not applicable
Author

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.

Not applicable
Author

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.

chancekbarkley
Partner - Contributor III
Partner - Contributor III

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. 

2017-03-16_10-54-39.png

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

Not applicable
Author

Thanks chance.k.barkley

I could achieve the expected outcome.

rohitk1609
Master
Master

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

anindya_manna
Partner - Creator II
Partner - Creator II

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.