How do I send file in a PUT resquest using Postman - json

I using postman to test my api, and I need to send a PUT request that has a json object and some files. Im sending raw data to test this but I cant seem to figure out how to add a file in there.
PUT request
raw data example:
{
"email": "someone#something.com",
"info": "new account",
"file1" : (some file should be here),
"file2": (some file should be here)
}

You are not supposed to send files AND data in a PUT request, either the body of the request IS a file content, either you use POST to have multiple files of a file with other data.
I honestly can't explain more as I am stucked with the same kind of problem :-)

Related

ADF, CopyData & Rest API

I actually try to make a simple pipeline to read JSON Data on a API REST and store it in a database.
I try first with a CopyData acticity.
I set up the linked service, the dataset, etc etc...
I need to call an API with POST Method and a Body's payload.
Everything is set, I launch the pipeline and... the api respond like i don't providethe Body's payload.
Double check it, check it via the generated json :
and in the generated pipeline JSON
...
"source": {
"type": "RestSource",
"httpRequestTimeout": "00:01:40",
"requestInterval": "00.00:00:00.010",
"requestMethod": "POST",
"requestBody": "{ \"startDate\":\"2022-09-01T00:00\", \"endDate\":\"2022-09-01T23:59\"}"
},
...
Because requestBody wait a string type, the double quote are escaped...
Never wanted to work. Nothing to do. API never seems to find the body.
I find the "Web" activity and I decide to give it a quick try.
Same api call,same linked service, same dataset same url, same method, same body payload...
Just a big copy&paste.
And it's work...
So, why Web activity works and not CopyData?
I reopen the generated pipeline's JSON and :
Web Activity:
"body": {
"startDate": "2022-09-01T00:00",
"endDate": "2022-09-01T23:59"
},
Copy Activity:
"requestBody": "{ \"startDate\":\"2022-09-01T00:00\", \"endDate\":\"2022-09-01T23:59\"}"
Seems that Web activity don't request the body type to be a String.
Maybe it's the problem,
Maybe Copy rewrite body "badly" and it's fail.
So,
Do I miss something?
or
Is it a bug?
And how do you do it? (consume API data in adf pipeline)
Cheers,
Mike.
You can use #json('{"startDate":"2022-09-01T00:00","endDate":"2022-09-01T23:59"}') in copy activity body
After using the above dynamic content, my copy activity receives the requestBody as an object. Look at the following image:
https://learn.microsoft.com/en-us/answers/questions/1000566/adf-copydata-amp-rest-api.html?childToView=1001129#answer-1001129
Just miss the additional header : content-type : application/json
...
:)

C# Sending Json body that includes a file

I have a C# project that
gets a request to do work
performs the work
returns to the api a json object containing the results of the request
This is working fine. As the work is done there is a log file that gets populated with various information (date being processed, errors encountered, etc.). I want to include a request type that would tell my program to return to the API the log file. Because I want this to be "just another request" I am trying to figure out how to include the file as part of the json body being returned. Is this possible? Is there a way to include a file (actual file - not just the contents of the file) in the json body?
I know how to return the file as it's own post - is there a way to return a json AND a file in the same post or am I looking at 2 separate post requests? One for the json body and a separate post that would send the file?

Issue while upload/send file with post request using Jmeter

I have one post request where I am uploading image as per below using postman :
I am trying to perform same request using Jmeter. I did following setting in Jmeter :
But somehow it is not working. I tried with multipart/form-data for POST option also but no luck.
our API developer has set validation that if api get any other file then image then they send response : invalid file type. I am getting this response all time when do POST request with image from Jmeter. It works fine with postman.
In Debugger post processor it shows like this : HTTPsampler.Files=path:'C:\apache-jmeter-4.0\bin\samplex.png'|param:'fileName'|mimetype:'image/png'
Finally I was able to resolve issue by removing Parameter name and MIME Type from tab File Upload. I did provide only file path and it works. Also I unchecked Use multipart/form-data for POST
You see button Browse.. in picture 2 you post. Do for same with Postman, choose file and send the request.
Make sure you have a valid file at the specified path.
Check your postman whether it is sending any other things in the header like Content-Type.
Check out File Uploads using JMeter guide for more information on simulating file uploads with JMeter
As I wrote in comment, If you want to send binary file as is (not as parameter value), remove the Parameter Name column value (file)
See JMeter's HTTP Request reference for more details:
File Path: Name of the file to send. If left blank, JMeter does not send a file, if filled in, JMeter automatically sends the request as a multipart form request.
If it is a POST or PUT or PATCH request and there is a single file whose 'Parameter name' attribute (below) is omitted, then the file is sent as the entire body of the request, i.e. no wrappers are added. This allows arbitrary bodies to be sent. This functionality is present for POST requests, and also for PUT requests.

How to test rest API with large json

I am writing rest api with Flask. One of my endpoints handles a post request. One field of the request JSON 'audio' is supposed to contain the BASE64 encoded PCM file (audio format). If save this field to a file, it is about 200KB.
It might be too big to copy and paste in Swagger or Postman for testing. Even worse with curl command. Is there any good way to test with really big JSON in the request.
I'd recommend a great tool called Insomnia. You can send point it to any file to send it as a HTTP request. You can change the Content-Type header to be application/json and select your JSON data file. Here's a screenshot of what the program looks like.

How to send the output of a GET REST request as body of POST request using Postman

For our application, we are supposed to write the test scripts which test our REST API.
So I have written individual tests in postman in a collection. When ran individually, all tests pass.
Now to run all tests sequentially in a collection, I want the output of the first GET request (the response is an array of JSON objects), to pass as input body to next POST request.
The following code is written as a test in Tests of GET request.
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("data", jsonData);
postman.setNextRequest("POST request");
I have named my post request as "POST request". But this test is failing.
Please let me know if I have done any mistakes.
You're trying to set the entire JSON as an environment variable instead of property value. Try to change your line like this.
const jsonData = pm.response.json();
pm.environment.set('data', jsonData);
Later, use that environment variable as input to your POST request as {{data}}
Considering your JSON response is something like this.
{
"status": "SUCCESS",
"message": null,
"error": null,
"id": 1234
}
Hope I answered your question. I have recently written a blog on automating API's using postman you can refer here API Automation using postman
Let us know if it solves your problem.
Ah!! Missed this point.
If you want to send the entire JSON as input then use JSON.stringify()
Similar question asked
The data should be set as part of the request for the POST operation.
Within Postman, in the body section for the POST request, you can set the data onto the request, either as a form field value or as the entire request body i.e. raw e.g.
{{data}}
Some additional information and examples are here: https://www.getpostman.com/docs/postman/environments_and_globals/variables