How to Post a multipart/form-data with different Content-Types in SoapUi - rest

I have a POST Rest-Request which consumes a multipart/form-data with an (optional) file part and a json part. Now I try to setup a SoapUi Rest-Request to test the ressource.
The equivalent request in postman for that json part looks like:
Key: someKey, Value: {"some": "json"}, Content Type: application/json
The equivalent cUrl Request is:
curl -X POST http://some-url -F "someKey={\"some\":\"json\"};type=application/json"
How to achieve this with SoapUi? I tried all possibles I can imagine, also a parameter with a file containing this json object like I found in a similar question.

Related

GET & POST passing parameters

I've read many question on stackoverflow about passing parameters with GET and POST methods, but none of them satisfied my curiosity.
I use GETs to retrieve data passing parameters as path/query params and use POSTs to save data passing parameters as request body with Content-Type: application/json and sometimes request body + path/query params (depending on other APIs I've created for simmetry purpose only).
My question is when to use Content-Type: application/x-www-form-urlencoded. Say I want to call a POST without a request body of Content-Type: application/json but with params, do I have to use the application/x-www-form-urlencoded Content-Type or I can use path/query params as best practice?
What's the difference between sending data as path/query params and key-value params with Content-Type: application/x-www-form-urlencoded? Does the data size have to do with it?
What's the difference between sending data as path/query params and key-value params with Content-Type: application/x-www-form-urlencoded?
Consider this example
PUT /example?a=b&c=d
Content-Type: application/x-www-form-urlencoded
d=e&f=g
What's happening here? This is a request that the server replace its current representation of the resource identified by
/example?a=b&c=d
With the payload. In other words, after successful processing, we would expect
GET /example?a=b&c=d
to produce a response like
200 OK
Content-Type: application/x-www-form-urlencoded
d=e&f=g
POST /example?a=b&c=d
Content-Type: application/x-www-form-urlencoded
d=e&f=g
For POST, it's the same idea, except that instead of "replace the current representation", POST stands in for "process the payload according to the specific semantics of /example?a=b&c=d".
GETs to retrieve data passing parameters as path/query params
It might help to reframe your thinking here. We use GET to retrieve the current representation of a resource. We aren't passing parameters, we're passing a document (resource) identifier.
The fact that the origin server's implementation is going to parse that identifier is an implementation detail.
A URI Template is a compact sequence of characters for describing a
range of Uniform Resource Identifiers through variable expansion.
-- RFC 6570
I want to call a POST without a request body of Content-Type: application/json but with params, do I have to use the application/x-www-form-urlencoded Content-Type or I can use path/query params as best practice?
POST /example?a=b&c=d
Content-Type: application/json
{"d":"e","f":"g"}
Is a perfectly normal HTTP request.
Content-Type describes the payload only - it has nothing at all to do with the target URI, and how information might be encoded within it.

HTTP GET from Tally - Whats the format of TDL?

I am trying to GET some data from another server into Tally via an XML API. But from the Tally documentation, I can see how to do HTTP POST. But I don't know what is the step by step process to do the HTTP GET using RemoteURL TDL instruction and pass the HTTP Header parameters. Can somebody please help? A sample would be a great help. Thanks!
To fetch data from a remote URL, if you are using POST, you would need to create a report and attach it to the request - this report is actually the POST payload.
POST Request:
[Collection: MakePOSTRequest]
Data Source: HTTP JSON: <insert URL here>
Remote Request: <insert TDL Report Name here> : UTF8
Export Header: <Insert header here>
JSON Object Path: "."
For GET request, you don't need anything except the URL. In case you have query parameters, attach it to the URL directly.
[Collection: MakeGETRequest]
Data Source: HTTP JSON: <insert URL here>
Export Header: <Insert header here>
JSON Object Path: "."
Let's say you have one URL: http://localhost:8000/get_api_data, which accepts both POST and GET requests. Then for the POST request, you would add the parameters via the TDL report, whereas for the GET request, you'd simply add the parameters to the URL this way: http://localhost:8000/get_api_data?key1='xxx'&key2='yyy'.
Not Working for me too..
[Collection: MakeGETRequest]
Data Source: HTTP JSON: 'http://35.198.189.9/api/Send?UserId=11&Guid=123'
JSON Object Path: "."

POST request with the REST Client extension for Visual Studio Code

I'm using the "REST Client" extension for Visual Studio Code https://marketplace.visualstudio.com/items?itemName=humao.rest-client.
I'm able to make a GET request with this code:
GET https://some.domain.com/search/someuser/somekey?foo=5&bar=1
and it works.
Now, I need to make a POST request and pass the foo and bar values as form fields.
I tried with:
POST https://some.domain.com/search/
Authorization: Basic someuser somekey
Content-Type: application/x-www-form-urlencoded
'foo'='5'
'bar'='1'
but I'm getting back an error "Missing required parameter foo in the post body"
What is the correct syntax for a POST request with REST Client?
Thanks.
It works like this:
POST https://some.domain.com/search/
Authorization: Basic someuser somekey
Content-Type: application/x-www-form-urlencoded
foo='5'&bar='1'
parameters need to be concatenated with &
parameter names should
not be put in between quotes

HTTPie returning "Error processing request. All request parts must have the content-type header set."

I'm testing an API with HTTPie. The implementation notes of the method I'm trying to use states that it accepts a multipart query containing a model in JSON format (Content-Type=application/json) and one or several files (Content-Type=application/octet-stream). I'm trying to post a file accompanied by a model in JSON. According to what I understood from the HTPPie documentation the way to do it is passing it as form:
http --form POST https://smartcat.ai/api/integration/v1/project/document documentModel#/path/to/json/file taskfile#/path/to/file\ projectId==xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
where projectId is a parameter to be sent as query string.
I've tried to set a Content-Type header for each file, however it doesn't seem right, as I expected the --form flag to set content-type as multipart/form-data, according to the documentation.
I'm sure I'm missing something basic, so any ideas on the direction to follow and how to better understand mime types are very welcome.

How do I send a JSON body as part of multipart/form-data with Paw?

I have a REST request that accepts multipart/form-data. This request is already working with an Angular front-end. It expects both an array of files in a parameter called files[] and a JSON body in a parameter with the name body. In Paw, it seems like I can get the multipart files to be recognized by my endpoint but the body doesn't appear to be the correct content type (application/json). Is there any way to specify the content type for each part of a multipart POST in Paw?
Details:
The error message I'm getting on the server-side is:
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
The config for the body in Paw is: