8 Replies Latest reply: May 9, 2018 4:05 AM by Rohit Kumar RSS

    REST connection POST method - QlikSense

    Gabriela Baldivia do Lago

      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.

        • Re: REST connection POST method - QlikSense
          Chance Barkley

          Gabriela,

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

          • Re: REST connection POST method - QlikSense
            Rohit Kumar

            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