Postman - How to sent .json file as POST data payload within pre-request scrpt? - postman

For the purpose of my testing, I need to fetch .json file at pre-request script section and use it as payload for POST request using Postman, then once been fetched need to alter some data on it.
My .json looks like:
{
"email": "test#gmail.com",
"password": "Abc12345",
"timezone": "Europe/Berlin"
}
After being fetched, I need to change email address with another dynamically generated email.
I know its possible to use .json file within body -> binary section of Postman, but this is not sufficient for the use-case that I need.
Is there any way to fetch .json file with-in pre-request script and then alter a value befere firing the request?

Related

Postman no longer returns the entire body of data in the query

Postman is no longer returning the same information as before.
I include a user using Ruby, when I go to query I can't see the data:
{"status":"success","data": {"name":"Zachariah","salary":8907.639999999999417923390865325927734375,"age":69,"id":580},"message":"Successfully! Record has been added."}
In this case on Postman: https://dummy.restapiexample.com/api/v1/employee/580
{"status":"success","data":null,"message":"Successfully! Record has been fetched."}

How to validate a file on S3 send by pre-signed URL?

I understand that a pre-signed URL is a way to send a file to S3. By doing that way, how can the object be validated? For example, I want to submit a JSON file to S3 and I want to make sure the file is in a correct format as input. I'd like to know if there is any way to make a response that the file is correctly saved and is valid by own validator function.
You could have an S3 event for create object that triggers a Lambda function. This could perform the validation checks you desire.
See: https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
The best way to do this is to generate the pre-signed URL with GET and PUT permissions for the same object. First, you would fire the PUT request to upload the file to S3 bucket. Next, you can do a GET call to check that the file has been uploaded.
As long as you are uploading a fresh new file, there is no chance of getting a false positive.
The above concept is based on the fact that the pre-signed URLs are restricted by time validating and not by the number of requests. This allows you to perform any number of PUT and GET call to the file as you want until the URL is valid.
Note: S3 is a trustworthy service - As long as you get a 200 status for your PUT request, you can rest assured that your file is there. The above method is just to crosscheck in case you wish to

In Postman Test script Can we execute another request in collection

In collection I have 5 requests. In one of a request I want to script in Test tab that after getting a response to execute a request already in the collection.
I cant find references/blogs/article for accessing requests in collection. Alternatively I can write a request. But I need to set authorization logic, and other settings.
Use the below script in the request from where you want to trigger the next request.
Note that request names has to be unique in a collection.
Refer this link for more details
postman.setNextRequest("Request Name")
Update
If you want to send a request after a single request is run, use
pm.sendRequest()
Refer this for pm.sendRequest
Note that pm.sendRequest has to include all parameters such as request URL, authentication etc., and is NOT a postman request self that is visible under a collection.

How to pass a request to sagemaker using postman

I've trained a model on sagemaker and have created the endpoint. I'm trying to invoke the endpoint using postman. But when training the model and even after that, I have not specified any header for the training data. I'm at a loss as to how to create payload while sending a post request to sagemaker
Here's an example for calling the sagemaker endpoint created in the quickstart guide. You can call it using text/csv or application/json formats:
In Postman:
The url you want is POST https://runtime.sagemaker.{{region}}.amazonaws.com/endpoints/{{aws_model_name}}/invocations
In the Authorization tab, choose type AWS Signature and put in the values for your AccessKey and SecretKey (recommend you use variables for these), and sagemaker for Service Name.
Under Headers add:
Content-Type : text/csv
Accept: application/json
In Body: paste in your body, separated by commas (if yr following the quickstart guide, in the notebook you can simply run print(valid_set[0][60:61]) to get an example vector. You'll need to convert that value set into comma separated values
Clicking Send and you should be good to go!
For sending JSON data, change the Content-Type to application/json and you'll want the structure to look like this:
{
"instances":[
{
"configuration": {},
"features": [...]
}
]
}
Once the endpoint is created, you can invoke it as any other restful service, with credentials and payload.
I am guessing, there could be two places where might be stuck.
One could be, sending an actual PostMan Request with all the headers and everything.
Newer version of Postman has AWS Signature as one of the Authorization types. You can use that to invoke the service. There are no other spacial headers required. Note that there is a bug in Postman still open (issue-1663) that only affects if you are a AWS federated account. Individual accounts should not be affected by this issue.
Or, you could be stuck at the actual payload. When you invoke the SageMaker endpoint, the payload is passed as is to the model. If you want to preprocess the input before feeding it to the model, you'd have to implement an input_fn method and specify that when instantiating the model.
You might also be able to invoke SageMaker endpoint using AWS SDK boto3 as follows
import boto3
runtime= boto3.client('runtime.sagemaker')
payload = getImageData()
result = runtime.invoke_endpoint(
EndpointName='my_endpoint_name',
Body=payload,
ContentType='image/jpeg'
)
Hope this helps.

How to send mail using gmail rest api from postmnan native application

My requirement is that send an email to some recipient with text body using POSTMAN Native app,
I used the below endpoint with requested data,
Base URL: https://www.googleapis.com/gmail/v1/users/userId/messages/send
Headers :Authorization:Bearer
Request Method :POST
Request body :{"raw";"to:user1mail#gmail.com","subject":"Test_Mail"}
Clicking Send button
But getting error response code 400,required recipient address
Please help me in this to send an email using POSTMAN,and I've tried with upload end point too -https://www.googleapis.com/upload/gmail/v1/users/user1email#gmail.com/messages/send
Thanks in advance,looking for help guys
Came across your question trying to figure this out myself today.
Request body : {"raw";"to:user1mail#gmail.com","subject":"Test_Mail"}
The raw param should be a complete email message that's base64-encoded.
i.e.: {"raw": "VG86IHVzZXIxbWFpbEBnbWFpbC5jb20KU3ViamVjdDogVGVzdF9NYWls"}
400 error means bad request, which could mean there are missing or wrong parameters. Check the Users.messages.send
Path parameters
userId string The user's email address. The special value me can be
used to indicate the authenticated user.
Required query parameters
uploadType string The type of upload request to the /upload URI.
Acceptable values are:
media - Simple upload. Upload the media only, without any metadata.
multipart - Multipart upload. Upload both the media and its metadata, in a single request.
resumable - Resumable upload. Upload the file in a resumable fashion, using a series of at least two requests where the first
request includes the metadata.