Chrome Postman REST: reusing response values as request params in collections? - rest

I'm playing around with Postman REST extension's collections feature.
I have 2 requests: the 1st returns a sessionId in its response body and the 2nd requires the {{sessionId}} value as query param. Can I tell Postman to save the body of the 1st response to the {{sessionId}} variable?
I currently have to a) execute 1st request and b) copy response body and paste it as a value of the 2nd request's query param every time...
thanks,
-nikita

Absolutely Yes!
Here is a json example:
I added the following to the Tests Tab of the first request:
var data = JSON.parse(responseBody);
postman.setGlobalVariable("session_id", data['session_id']);
Basically retrieving the data from responseBody and set it as a global variable
Then in the second request, the URL would be something like this:
http://{{whateverhost}}/api/v1/somefunction/{{session_id}}
Hope this helps.
Cheers

Related

How can I put header parameter in a Url?

I want to get data from API. So first I want to get Json response from the browser. I Usually do it by specifying a query to pass the API key. But this time the API key is passed using header parameter instead of a query. How can I pass the API into a header parameter?
This is the base Url
"https://api-nba-v1.p.rapidapi.com"
This is the header parameter:
x-rapidapi-key
You can try to issue this request first using some rest client like postman or insomnia.

Is there an option to remove the multipart content set in request in REST API(RestAssured) after getting a response?

In REST API, specifically RestAssured, there is an option to remove the Query params, Headers, Cookies, Form params, Path params which is set in request after getting a response.
Is there an option to remove the multipart content set in request in REST API(RestAssured) after getting a response?
If you're looking a way to reuse the RequestSpecification object, then No, there are no reset method for all of these config.
You can create new RequestSpecification object each time you call the request. Sample here. https://stackoverflow.com/a/69569031/7574461

How to get response headers in neo4j - apoc.load.jsonParams()?

I have the following CQL apoc query in neo4j that works fine to get response payload from a rest GET request:
CALL apoc.load.jsonParams($uri, {Authorization: $Bearertoken}, null)
YIELD value
UNWIND value.items AS item
RETURN item
However, the uri uses pagenation and the next page uri is present in the response header. Therefore, I need a way to retrieve the response header along with the value. Please let me know if there is a way to do this.
Thanks in advance.
The apoc.load.jsonParams procedure does not support returning the response header.
You can write your own code instead. Here is an article that can help get you started.

Trying to do some assertion from request, which will be present in response

I am passing the request as in my feature file and i am trying to do assert from request to response.
I have tried must contains queries but i am not sure if i am doing it correct, could you please help.
**Background:**
* configure headers = read('classpath:merchantServiceheaders.js')
Given url MservUrl
And path '/spapis/rest/sp-ms-engine/sp/ms/v1/engine/scanandredact'
Scenario Outline: ACH Low Value Payment Rips Services Summary
]
}***
What i would like to do is assert what i have in my request to what i will get back in response.
Since i am passing subject in request the same subject should be present in response
Possible in 0.9.3: https://github.com/intuit/karate#scenario-outline-enhancements
First change the Examples: column header to data!
And request data
When method post
Then status 200
And match response contains data
In 0.9.2 and earlier, with the Examples: column header as data
* def data = <data>
And request data
When method post
Then status 200
And match response contains data

POSTa Request with rest assured api using XML Payload

I am in need of one requirement.I want to POST a request using Rest Assured API using XML payload,I did not get any where how to set the body using XML. any one please tell me how I can achieve this.
I have one table customers with 5 fileds,name,id,address,email and phone number.My URL to post the request is something like
"http://com.myproject.app:8080/MyApp/SchmaName/customers".Please any one help me out.Thanks in advance
The above should work, here it is again in a slightly different version with your example...
Response response = given().
contentType("application/xml").
body(myXML).
when().
post("http://com.myproject.app:8080/MyApp/SchmaName/customers");
myXML would be the xml you want to send (5 fields; name,id,address,email and phone number). After that you can pull the result from response.
You can just post in the request body as a String, InputStream, byte[] or a Java object (that will be serialized to XML using JAXB). For example:
String myXML = ..
given().contentType(ContentType.XML).body(myXML).when().post("/x").then(). ..