Created on 03-05-2024 06:31 AM - edited 03-05-2024 06:50 AM
Hello, I m sending a http requestto an API and facing some difficulties to configure the multipart specificities.
The 1st part should be binary (gzip) and named (data) and the second part should be json file and named (parameters). this works corretly with post man
but I m not able to do the same thing with Nifi 1.18
this is my workflow
if someone faced this situation, plz share your feedbacks
Created 03-05-2024 08:45 AM
@bou7miiiz Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi experts @mburgess @MattWho who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Created 03-05-2024 07:24 PM
Hi @bou7miiiz ,
Its hard to tell what is wrong from what you provided because you seem to everything setup accordingly but Im not familiar with what type of API you are working with so its hard to tell. First, I would like to know what is happening when you run the InvokeHttp? are you getting an error? what type of error and response code are you getting?
Second, I noticed in Postman you are referencing the json parameters value form a file, did you try to pass the json itself instead because that is what you are doing with Nifi.
Created 03-06-2024 01:29 AM
thank you for your answer Samsal,
its a rest API via HTTP
the invokHttp is not throwing any error
and m getting a 415 error with an empty response
and yes when I try to change the file in postman with a text, I get the same error
< 415 Unsupported Media Type
< accept: application/json, application/cbor, application/xml;charset=UTF-8, application/*+json, text/xml;charset=UTF-8, application/*+xml;charset=UTF-8
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< content-length: 0
< content-security-policy: frame-ancestors https://sgconnect-hom.fr.world.socgen 'self'
< date: Wed, 06 Mar 2024 09:23:07 GMT
< expires: 0
< pragma: no-cache
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-content-type-options: nosniff
< x-frame-options: DENY
< x-xss-protection: 1; mode=block
however, when specifying the content type for the parameters it's working (in postman)
the probleme is that I m not able to specify the second content type "application/json" and it's mandatory either with file or text
Created 03-06-2024 02:37 AM
This is interesting. I never came across a case where you need to specify the content-type on the form data itself & I cant find anything for that in the invokehttp documentation. @MattWho , @cotopaul , @joseomjr do you have any information on this?
When I look into how the type is passed using curl for example, it looks like the following:
--form 'Parameters="...";type=application/json'
I'm not sure this is going to work but when you set the post:form:parameters value try to append the type to the json string as follows:
${JSONAttributes:append(";type=application/json")}
If that doesnt help. Im not sure how can you do such thing without using something like ExecuteScript processor and write code like groovy to execute the API call.
I apologize if I did not have straight answer.
Created 03-06-2024 05:16 AM
unfortunatly it's not working, however if this can help, in Nifi 1.11 i m using a groovy script (I thought that I can avoid it by migrating to 1.18)
Created 03-11-2024 11:20 AM
@bou7miiiz are you setting the mime type in the post HEADERS from nifi to the api?
The 415 error seems to be expecting "application/json".
Add this property the same way you added Authorization.
Created 03-12-2024 09:41 AM
how can I add this property to the invokHttp? I should precise that this content-type is only for the json part. the other part should be application/octet-stream
Created 04-09-2024 01:48 PM
What headers do you set inside of Postman?