Reputation: 1
Greetings!
I am working on automating dummy POST API request with Authorization.
Please check below details for the same,
**Code:-
RestAssured.baseURI="http://restapi.adequateshop.com/api/users";
String jsonBody = "{\"tourist_name\":\"Mike\",\"tourist_email\":\"[email protected]\",\"tourist_location\":\"Paris\"}";
String token="433tc02b-b5c1-4bd8-836a-618cdc31c492";
Response response = RestAssured.given()
.header("Authorization", "Bearer " + token)
.header("User-Agent", "PostmanRuntime/7.32.3")
.header("Accept", "*/*")
.header("Connection", "keep-alive")
.body(jsonBody)
.post("http://restapi.adequateshop.com/api/users");
int statusCode = response.getStatusCode();
String responseBody = response.getBody().asString();
System.out.println("Response Code: " + statusCode);
System.out.println("Response Body: " + responseBody);
After execution, received 401 Response and expected response is 201.
This same API is working with POSTMAN and received 201 response.
Please check below POSTMAN screenshots for API collection details,
Please guide me how to resolve this?
I tried above code but getting 403 response code. How to resolve this issue?
Upvotes: 0
Views: 77