API Automation Testing – Interview Questions & Answers
1. What is API Automation Testing?
API Automation Testing is testing APIs using code instead of tools like Postman. We validate status code, response body, headers and performance using automation scripts.
2. Why automate API testing?
Faster than UI, stable, easy to integrate with CI/CD, validates backend logic early.
3. Which languages can be used for API automation?
Java, Python, JavaScript, C#, Kotlin etc.
4. What libraries are used for API automation?
Java → RestAssured, Apache HttpClient Python → requests JS → axios, fetch, supertest C# → HttpClient, RestSharp
5. How many ways can we call API in automation?
Main ways: 1. Using REST libraries (RestAssured, requests) 2. Using low-level HTTP clients 3. Using framework tools (TestNG/JUnit) 4. Using BDD (Cucumber + API) 5. Using built-in language support
6. How to call GET API in Java (RestAssured)?
Response res = given()
.baseUri("https://reqres.in")
.when()
.get("/api/users/2");
System.out.println(res.getStatusCode());
System.out.println(res.getBody().asString());
Explanation:
given() → request
when() → action
then() → validation
7. How to call POST API in Java?
String body = "{ \"name\":\"John\", \"job\":\"QA\" }";
given()
.contentType("application/json")
.body(body)
.when()
.post("/api/users")
.then()
.statusCode(201);
8. How to call API using Apache HttpClient?
HttpGet request = new HttpGet("https://reqres.in/api/users/2");
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(request);
Lower level, more coding needed.
9. How to call API in Python?
import requests
url = "https://reqres.in/api/users/2"
res = requests.get(url)
print(res.status_code)
print(res.json())
10. How to call API in JavaScript?
fetch("https://reqres.in/api/users/2")
.then(res => res.json())
.then(data => console.log(data));
11. How to pass headers in API automation?
given()
.header("Authorization","Bearer token123")
.get("/api/users");
12. How to pass query parameters?
given()
.queryParam("page",2)
.get("/api/users");
13. How to validate response body?
.then()
.body("data.id", equalTo(2));
14. How to extract value from response?
int id = res.jsonPath().getInt("data.id");
Used for chaining APIs.
15. What is API chaining?
Using response of one API as input to another API. Example: Login → get token → use token in next API.
16. How to handle authentication in API automation?
Basic Auth, Bearer Token, OAuth.
given().auth().basic("user","pass")
17. How to automate DELETE API?
given().delete("/api/users/2")
.then().statusCode(204);
18. How to do negative testing in API automation?
Send wrong input and validate error message and status code.
19. How to integrate API automation with TestNG?
Create test methods and assertions.
20. How to integrate API automation with CI/CD?
Using Maven + Jenkins + Git.
21. Difference between manual and automated API testing?
Manual → Postman Automation → Code based and reusable
22. What challenges in API automation?
Token handling, dynamic data, complex JSON, environment issues.
23. What is serialization?
Converting object to JSON.
24. What is deserialization?
Converting JSON to object.
25. What is schema validation?
Validating response structure using JSON schema.
26. Can we automate SOAP APIs?
Yes, using XML requests and validating XML responses.
27. What is idempotent API?
Same result even if called multiple times (GET, PUT, DELETE).
28. How to log API request and response?
Using logging filters.
29. What is retry logic?
Retry API call if it fails.
30. Explain your API automation framework.
Using RestAssured + TestNG + Maven + JSON files + Jenkins.