Reputation: 1
package com.automation.tests;
import static io.restassured.RestAssured.*;
import org.json.JSONObject;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
public class AspenTest {
public static void main(String[] args) {
JSONObject churnUsageBody = new JSONObject();
churnUsageBody.put("customer_id", "c096");
RequestSpecification sp = given().baseUri("http://192.168.180.12:4000/")
.header("Content-Type", "application/json")
.header("X-CSRFToken", "EZpbczzL5yiBHKT0fn2PcfPszp0IfHwPLn3pmXJYA8BX8bH6Gn6ILrlAJPSuX1uq")
.header("Authorization", "Token d2618176b9b9aed6dc0a9cb3a1ebfe1c4c8831ed999bdce4432e061aa56f672f")
.body(churnUsageBody.toString());
Response rs = sp.post("churn/app/usgscore");
System.out.println(rs.asPrettyString());
}
}
I am trying to run the api after adding the authorization token, I am getting the below error, even the token is proper and this api is working in postman also.
{
"detail": "Authentication credentials were not provided."
}
Upvotes: 0
Views: 44
Reputation: 521
To debug the issue, I have two suggestions for you:
please check whether the API expects the word "Token" before the actual token. Some APIs expect "Bearer" before the actual token. {.header("Authorization", "Bearer d2618176b9b9aed6dc0a9cb3a1ebfe1c4c8831ed999bdce4432e061aa56f672f")}
Log your request by enabling logging ( log().all()) in rest assured to debug your request and verify that the headers and body are being sent correctly. Resource
Upvotes: 0