Setting token retrieved from response in Postman - postman

In tests section, I try to set token as Postman variable. I get the following error:
SyntaxError: Invalid or unexpected token
Here's my script in test tab:
var data = pm.response.json();
pm.environment.set(“token”, data.token);
and here's my response for login:
{
"id": 1,
"username": "admin",
"name": "John",
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTU2OTY3ODg4NSwiaWF0IjoxNTY5MDc0MDg1fQ.k6aMQYo9uzC9jEXFvP1EZEUNEG_7VgEKxKmNtrZ9rSYvViHCNGYMaEpYY7MH8rYgtIg1Lpi4bfZEd9q2iOEOSQ"
}
Content type of response is application/json;charset=UTF-8.
What am I missing?

Notice the difference between " and “
pm.environment.set(“token”, data.token);
should look like this
pm.environment.set("token", data.token);

Related

sendOobCode Google Identity Platform

I'm trying to use Google Identity platform api's with my firebase project ( I configured a payment method to use the identity platform sendOobCode and sendVerificationCode methods. But I keep receiving a 400 ERROR.
I tried using the built-in api calls in the console and got back more detailed errors.
"errors": [ { "message": "CONFIGURATION_NOT_FOUND", "domain": "global", "reason": "invalid" } ] }
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
var url = 'https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[]';
var data = {
// requestType: "VERIFY_EMAIL",
idToken: userCredential._tokenResponse.idToken
}
console.log(userCredential)
axios.post(url, data, {
headers: {
'Content-Type': 'application/json'
}
}).then((res) => {
console.log(res)
}).catch((err) => {
console.log(err)
})
})
.catch((error) => {
.....
})
So I was able to get more information on my error by going into the Network Section in the dev tools. I checked the 400 request error and found in the response that I have an invalid API key. I forgot to remove the [] :)

Can Postman access posted values in a test

I have postman set up to post data to an endpoint. Ex:
{
"gender": "f",
"firstName": "bob",
"lastName": "smith"
}
I have a test that extracts information from the response and stores it in environment variables.
Is there a way to access the values that were posted as part of the test. Something like:
pm.request.parameters("gender")
As per the postman sandbox documentation, you can do the following:
var reqBody = JSON.parse(pm.request.body);
... // Access reqBody;
To get access to that specific property:
JSON.parse(pm.request.body.raw).gender
And the test could be:
pm.test("Check request data", () => {
pm.expect(JSON.parse(pm.request.body.raw).gender).to.eql('f')
})

NaN error displayed when I use pm.request.body.raw in Postman

I pass the below params in the request body:
{
"locale": "en",
"type": "abc",
"model": {
"id": "123"
}
}
in raw JSON format.
I am trying to retrieve the same params in the test tab using requestBody= JSON.parse(pm.request.body.raw); but then I get a NaN when I write the output to the console.
How could I retrieve the params sent in body request to my test scripts?
You can use this in the Tests tab to log any value from that request body:
console.log(JSON.parse(pm.request.body.raw).locale)
console.log(JSON.parse(pm.request.body.raw).type)
console.log(JSON.parse(pm.request.body.raw).model)
console.log(JSON.parse(pm.request.body.raw).model.id)

Facebook graph: error in after cursor

when I make a get request on facebook graph api, for page search, everything is fine. But when I use the after cursor or click on the 'next' field I get the following error:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "B4oyy5hYamh"
}
}
until yesterday everything worked perfectly, but today I found this problem.
this is my first request:
https://graph.facebook.com/v2.10/search?access_token=*******&fields=about,paging&type=place&center=41.817557,12.446137&categories=["FOOD_BEVERAGE"]&distance=2000&limit=25
and this is the request for the next page:
https://graph.facebook.com/v2.10/search?access_token=*******&fields=about,paging&type=place&center=41.817557,12.446137&categories=["FOOD_BEVERAGE"]&distance=2000&limit=25&after=QWJwc3kyZAklVTVpZAMmlEd0hFdXRINWVOU2hPSDQ5SWtYcXFreHFGX2pTVndHMW9DOV9BTmgtVGlxN04xUDJheXRCSGZAabjZAxUVJnbE5wRmcyMU4yQ3J3ZAkRqVVE1NHpjQWhPZAkh5clA1MnUxNV9WTzU1TngzYlhfVkRfZAGs2SWZAkNXNFQ3RQWEd2Rk1hNXdGRW5vdmlNbFh3aDl4YzlSdmxWUkQ4RzFGTnFZAbUxqYzhnMFZASYkxuWHJobUttSkdwZAWZANUnkwN1AyQm93Tnh1bnYwT0ZAEMVRyYXhZAMldFNF9SNjlCMGttWmZA6SGdKSUN4aXZAyLVZAmOUJ4RnM3SFJRNHNUY3lUNDUyOGo2VTdrWUJYcDh3SVd2dDdOWlBzZAUhPZA0tzY0czM25hU25iNmI0ZATN0UFFQZAGlJSFdEd2J3bVUycUZAvNE5YVEw4QlJmTUJmNlpvUWd0Y1pQOE9aWnpKOFlkZAFIxcTU2UXBJTzRR
Your after seems incorrect, it should be a very short code. Have you pasted an access token instead?
This query
https://graph.facebook.com/search?q=food&type=page&limit=3&access_token=ACCESS_TOKEN returns
{
data: [
{
name: "Food Network",
id: "20534666726"
},
{
name: "FOODbible",
id: "996909263665350"
},
{
name: "Food",
id: "113109208703114"
}
],
paging: {
cursors: {
before: "MAZDZD",
after: "MgZDZD"
},
next: "https://graph.facebook.com/v2.5/search?access_token=ACCESSTOKEN&pretty=1&q=food&type=page&limit=3&after=MgZDZD"
}
}
so to fetch the next list, I simply append the after value (MgZDZD) to my initial query to fetch the next page of results. eg
https://graph.facebook.com/search?q=food&type=page&limit=3&access_token=ACCESS_TOKEN&after=MgZDZD

Mulesoft Anypoint Platform Mock service

I have a problem Working in Api manager of the Anypoint platform at https://anypoint.mulesoft.com/apiplatform..
I made an API Raml definition and am testing all endpoints using the Mock service. So when making a call to the Api endpoint a mock baseurl is provided and the response consists of the example provided with the called endpoint / http verb. This works fine for GET but when doing a 'Try It' for the POST I get
status 400 error
{
"error": "body: person: required"
}
as a response. No matter how I provide the body parameters. My endpoint POST definition is:
post:
body:
application/json:
properties:
person:
required: true
type: object
token:
required: true
type: string
example: |
{
person: {
"firstName": "John",
"infix": "",
"id": "605a0302-cc33-449a-ac50-5ef26e3e3330",
"emailaddress": "john#doe.nl",
"lastName": "Doe"
},
token: '42E2BC51-6C62-6D46-AC1457446EC4C737'
}
In the Api workbench' Mocking service pane I enter this in the body:
{
person: {
"firstName": "John",
"infix": "",
"id": "605a0302-cc33-449a-ac50-5ef26e3e3330",
"emailaddress": "john#doe.nl",
"lastName": "Doe"
},
token: '42E2BC51-6C62-6D46-AC1457446EC4C737'
}
but I still get "error": "body: person: required" also if I omit token ....
What am |I doing wrong here???
Ok., turns out devil's in the details. Input was bad formed json - should surround keys with "" and no singleqoutes for the token value... :(
the json format defined in the raml is not proper one, can you change the raml exmple to a valid json format and test it. it will work fine