CURL multipart/form-data

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Frank2
Posts: 21
Joined: Tue Nov 17, 2020 10:33 pm

CURL multipart/form-data

Post by Frank2 »

Hi guys,

Can someone maybe advise me how the do the api call in Aware for multipart/form-data.(Content-Type)

This is what the CURL looks like.

curl -X 'POST' \
'https://baseURL.....' \
-H 'accept: application/json' \
-H 'Authorization: Token' \
-H 'Content-Type: multipart/form-data' \
-F 'type=email' \
-F 'value=emailaddress' \
-F 'Varaible3=true' \
-F 'Variable4=false'

Will I add it to the "Use this string" section or "Take from Context" section? (RESTService->Paramaters->RequestBody)

Thanks
Francois
Frank2
Posts: 21
Joined: Tue Nov 17, 2020 10:33 pm

Re: CURL multipart/form-data

Post by Frank2 »

Hi Jaymer,

Any idea how to do the above?

Thank you very much.

Francois
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: CURL multipart/form-data

Post by Jaymer »

frank
there's lots of ways to do this.
sometimes its in the String, other times you build a complex string and put it in a field, then have that record in context and let it send it from there.
it just depends on what you need to send and how complex it is.

what have you tried?
you already know about putting 2 fields together. why didn't you just continue to build the string with 4 fields?:

type=email&value=<<customer.emailaddress>>&variable3=true&variable4=<<customer.activeYN>> etc etc
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: CURL multipart/form-data

Post by Jaymer »

another thing - and I was going to say this on your First REST question.

You are not helping us when you make up a 'scenario' - rather than just supply a correct link to an API you are trying to use.
It would have been a lot easier to see the original requirements in the API docs than to try and figure out what you are doing.
Just saying... if you want help, its easier this way.

For example in this one, there are fields in the header. Do you have those figured out?
You maybe put to much emphasis on multipart/form-data or application/json. Usually, thats handled for you. Just worry about the data first.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Frank2
Posts: 21
Joined: Tue Nov 17, 2020 10:33 pm

Re: CURL multipart/form-data

Post by Frank2 »

Hi Jaymer,

This is the actual API call as published in the API documentation:

curl -X 'POST' \
'https://if.cyberintelligencehouse.com/a ... 6e-9a14f07' \
-H 'accept: application/json' \
-H 'Authorization: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJMOXd2a29DcGRwUEVvZ3hjUF85aE0tcnVvTTQ4NTA1cS1yN3hvdTUwNnlrIn0.eyJleHAiOjE2Nzc2Njk4OTksImlhdCI6MTY3NzY2ODA5OSwianRpIjoiNTc0MjVkYWYtMDU3NC00YTM1LWJkNTItZGI0NWIwYmJjNTRjIiwiaXNzIjoiaHR0cHM6Ly9hdXRoLmN5YmVyaW50ZWxsaWdlbmNlLmhvdXNlL2F1dGgvcmVhbG1zL0NJSCIsImF1ZCI6WyJtb25pdG9yaW5nMiIsImFjY291bnQiXSwic3ViIjoiZGJjNjg1MmItYjE5Mi00MTgyLWFjMzg' \
-H 'Content-Type: multipart/form-data' \
-F 'type=email' \
-F 'value=[email protected]' \
-F 'start_update=true' \
-F 'create_asset=false'

Unfortunately I can't provide you with a link to the API. I have tried to built the string as you suggested but the error that I get is that it receives an empty value. See attached screenshot.
APIError.PNG
APIError.PNG (11.05 KiB) Viewed 991 times
The difference between the two POST calls was this: See Curl below.

curl -X 'POST' \
'https://if.cyberintelligencehouse.com/a ... de3d9b565c' \
-H 'accept: application/json' \
-H 'Authorization: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJMOXd2a29DcGRwUEVvZ3hjUF85aE0tcnVvTTQ4NTA1cS1yN3hvdTUwNnlrIn0.eyJleHAiOjE2NzcyMzQ2OTMsImlhdCI6MTY3NzIzMjg5MywianRpIjoiZGU0NjBkMTUtZWRmNi00ZDNiLWIyNDgtYWE3Nzc5OTU3NmQzIiwiaXNzIjoiaHR0cHM6Ly9hdXRoLmN5YmVyaW5hvcml6YXRpb24iLCJkZWZhdWx0LXJvbGVzLWNpaCJdLCJuYW1lIjoiQ2FyYSBEaXBwZW5hYXIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJjYXJhMSIsImdpdmVuX25hbWUiOiJDYXJhIiwiZmFtaWx5X25hbWUiOiJEaXBwZW5hYXIiLCJlbWFpbCI6ImNhcmFAY3liZXJxZ3JvdXAuY29tIiwiZ3JvdXAiOlsiL01vbml0b3JpbmcvQ3liZXJRIE1TU1AgQW5udWFsIFN1YnNjcmlwdGlvbiJdfQ.AmTkDkUUgqXaBClBVQl9dJj1gVUN3Rjp02m7Kjj4OAavu047rSEpr7h-voW0e6Rq-lu_0gyyAn8Bh4GbUZXEGLEd6yByvdcHs6KlGp3DwJy2gPN5r0PDNdzj0mNnGxVlI-4K-7_kBwummiex_0CaLbNFeMT59-LGrWnr8RUgPBKvB3Efb0s5l3wzfnOW7JA97qDMBuyqeSMlf1PdQ91ZmDWWFaJxw-wpSUsiWFtEdyAoc5wsr_wDjfvegJ41ZZil0idfe_pm8zg5c2kjEfMFBNzYb8yHNh-S_VIlzHai2x0NPeXypL5UlidGYDWcddU-7KOJ9kTXIrULb6-gXIoJLw' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'name=Francois'

1.In the last example above that is now working with the solution you gave me was that the Body data was passed through as "-d"
When you pass data to Curl with the -d command line argument, Curl, by default, sends the data to the server in the Content-Type: application/x-
www-form-urlencoded format.

2. In the API Post call that I am struggling with is that the Body data is sent through as "-F"
What does cURL F mean API?
-F tells curl to emulate a filled in HTML Form that has just had it's submit button clicked

So to get to the point. I can not send the data to the API in the same way by building a string as in my first API POST where I could build a String in Aware because it gives me an error.
I have now tried everything, saving the data in an Object in Context and then passing it to the API. Even in JSON format(which the API does not support). Building a string and assigning the value to a single attribute in an Object in context and then passing it to the API,etc..

I hope all of this makes sense :-)

Thank you for your help. I really appreciate it.

Kind regards,
Francois
Frank2
Posts: 21
Joined: Tue Nov 17, 2020 10:33 pm

Re: CURL multipart/form-data

Post by Frank2 »

Hi Jaymer,

Just some feedback. Figured it out.

Had to change the Content Type in the Header to "Content-Type: application/x-www-form-urlencoded" instead of the 'Content-Type: multipart/form-data'(Which is actually required by their API). With that it allows me to build a string and send it to the API.

Thanks,
Francois
Post Reply