Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
AG-gugelbisolutions
Creator II
Creator II

POST request to REST webservice

Hi there, I have a bit tricky issue to submit to you.

The goal is to POST some data to an endpoint by means of Qlik Sense. I tried at least three different ways to get there, but neither one was successful.

#1 - Qlik Sense REST (built-in) Connector

--qliksense Content-Disposition:form-data; name="InventoryOptimization" false --qliksense--

The error message is as follows:

HTTP protocol error 500 (Internal Server Error): {"Message":"An error has occurred.","ExceptionMessage":"Unexpected end of MIME multipart stream. MIME multipart message is not complete.","ExceptionType":"System.IO.IOException","StackTrace":" at System.Net.Http.Formatting.Parsers.MimeMultipartBodyPartParser.d__15.MoveNext()\r\n at ...

This might seem to be a server side related error, but the same configuration works in Postman!

#2 - Qlik General Web Connector / RawResponse

I basically used the same settings as for the previous attempt, but this time the error is more verbose:

There was an error running the table (status code = 500, Failed on attempt 1 to POST. (Errore del server remoto: (500) Errore interno del server.), HttpStatusCode: InternalServerError, StatusCode: 500, StatusDescription: Internal Server Error, Message: Errore del server remoto: (500) Errore interno del server., ResponseBody: {"Message":"An error has occurred.","ExceptionMessage":"Unexpected end of MIME multipart stream. MIME multipart message is not complete.","ExceptionType":"System.IO.IOException","StackTrace":" at System.Net.Http.Formatting.Parsers.MimeMultipartBodyPartParser.<ParseBuffer>d__15.MoveNext()\r\n at System.Net.Http.HttpContentMultipartExtensions.<MultipartReadAsync>d__10.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Net.Http.HttpContentMultipartExtensions.<ReadAsMultipartAsync>d__9`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at SO99WebClient.Controllers.SelfServiceApiBaseController.<GetFormItems>d__8.MoveNext() in C:\\Development\\alopez\\WEBCLIENT\\840SP6\\SO99WebClient\\Controllers\\SelfServiceApiController.cs:line 115\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at SO99WebClient.Controllers.CalculationLaunchController.<Get>d__0.MoveNext() in C:\\Development\\alopez\\WEBCLIENT\\840SP6\\SO99WebClient\\Controllers\\SelfServiceApiController.cs:line 367"})

#3 - WITH CONNECTION SELECT statement

I also tried to build the request in a rawer manner

LET vContentType = chr(34)&'multipart/form-data;boundary='&chr(34)&chr(34)&'qliksense'&chr(34)&chr(34)&chr(34);
LET vBody = chr(34)&'--qliksense Content-Disposition:form-data;name='&chr(34)&chr(34)&'InventoryOptimization'&chr(34)&chr(34)&' false --qliksense--' & chr(34);

SQL SELECT "Launched"
FROM JSON (wrap on) "root"
WITH CONNECTION (
URL "https://xxxxxxxx.azurewebsites.net/api/CalculationLaunch",
HTTPHEADER "Authorization" "yyyyyyyyyy",
HTTPHEADER "Content-Type" $(vContentType),
HTTPHEADER "Accept" "*/*",
BODY $(vBody)
);

But it turns out there must be at least one working POST connection to be established before this snippet can be successfully run. the point is that WITH CONNECTION cannot override the method used.

 

Anyone with better ideas?

Labels (2)
4 Replies
Qlik_Eric_Thomas

Unfortunately, cannot give too many specific tips as i'm not familiar with the API you are using. Since you were able to get the POST request working in Postman, maybe we can find the delta between how that request is being made and your REST Connection in Qlik Sense. 

I'd suggest using the 'Code Snippet' functionality in Postman (HTTP specifically) to see if any additional headers are being sent that is making this successful. Compare the 'Content-Type' Header as well to see if the 'boundary' portion of your 'multipart/form-data' is being sent the same. 

You can also play around with some of the Postman settings like 'Automatically Follow Redirects' to see if that needs to be accounted for. 

Sr. Technical Support Engineer with Qlik Support
Help users find answers! Don't forget to mark a solution that worked for you!
AG-gugelbisolutions
Creator II
Creator II
Author

Hi @Qlik_Eric_Thomas  and thanks for the quick reply.

I actually based the header list on what I could see in Postman, even though I only kept those that did not make me fall into a Bad Request error, at the end.

Content-Type/boundary and the request body appear to be exactly the same between Qlik Sense and Postman, except for the boundary: Postman uses  a series of "-" followed by "postman"; I have used "qliksense"; and this leads to request body I mentioned in my first post.

I took a look to the HTTP code snippet but it didn't help. It reflects I slightly different use of the boundary value (i.e. declared without " and used without "--" to indicate the end of the form data), which I tried without success.

Any other ideas?

Qlik_Eric_Thomas

What type of file is 'InventoryOptimization' or is that the value that needs to be passed?

If it's a file, I would expect something more like this: 

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="Path"; filename="/C:/Users/TestUser/Downloads/App Analyzer (1).qvf"
Content-Type: <Content-Type header here>

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW

The (data) portion would need to be a byte array of the file you are using: https://cloudmersive.com/convert-file-to-json-byte-array-tool

If it's not a file, see if the API specifications would allow you to use a different 'Content-Type' to pass your BODY value. 

I have not tried passing a file like this and don't really have an API in mind I could test with. 

Sr. Technical Support Engineer with Qlik Support
Help users find answers! Don't forget to mark a solution that worked for you!
AG-gugelbisolutions
Creator II
Creator II
Author

Hi @Qlik_Eric_Thomas , IntentoryOptimization is a boolean value, so I did not expect that kind of error message; on the other hand, it works with Postman and this puzzles me...