tolga
tolga

Reputation: 2800

Setting token retrieved from response in 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?

Upvotes: 0

Views: 388

Answers (1)

Dev
Dev

Reputation: 2813

Notice the difference between " and

pm.environment.set(“token”, data.token);

should look like this

pm.environment.set("token", data.token);

enter image description here

Upvotes: 2

Related Questions