Testing the API with Postman
When you created a schema, you might want to test the output. You can do so in Postman. This article will tell you how to do so.
Using Postman to Test Schemas: ReadMe Documentation
This guide explains how to use Postman to test and validate schemas effectively. Postman is a powerful tool for API development that allows you to send requests, validate responses, and test schemas for compliance.
Prerequisites
Before testing schemas with Postman, ensure you have:
- Postman installed on your system. Download it from Postman’s website.
- A basic understanding of API requests and responses.
- Access to the API you wish to test, including:
- Endpoint URL
- Authentication details (if required)
- API documentation
- The schema you want to test (e.g., JSON Schema).
Setting Up Your Environment
- Go to the Environments tab in Postman.
- Create a new environment and add variables for dynamic values, such as:
base_urlapi_key
- Use these variables in your requests (e.g.,
{{base_url}}/endpoint).
Creating Requests
- Go to the Collections tab and select your collection.
- Click Add Request to create a new request.
- Fill in the Request Type: GET, POST, PUT, DELETE, etc.
- In the URL bar, add the BaseURL and add the endpoint to the BaseUrl. E.g. [https://api.example.com/orders/id/
- Go to Params, add the Key and the Value to test.
- Navigate to Authorization and copy and paste this from Watermelon.
- Fill in the details:
- Headers: Add necessary headers (e.g.,
Content-Type: application/json). - Body: Add the request payload if required.
- Headers: Add necessary headers (e.g.,
- Click on Send.
- If the response is 200 ok than it means that your API call is working.
- Save your request.
Note: Ensure that your API schema is valid and complete before testing any API calls.
Troubleshooting Common Errors in Postman
Even when your setup looks correct, you may encounter error responses instead of the expected 200 OK. Here’s what to do when that happens:
400 Bad Request
This means the server couldn’t process your request because of something invalid in the request itself. Common causes:
- Malformed JSON in the request body.
- Missing or incorrect parameters in the query string or body.
- Headers not set correctly, such as forgetting Content-Type: application/json.
What to do:
- Double-check your request body and ensure it matches the API schema exactly.
- Verify required parameters are present and correctly formatted.
- Check the documentation for expected header values (e.g., authentication token, content type).
404 Not Found
This means the resource you’re trying to access doesn’t exist (or the endpoint URL is wrong).
What to do:
- Confirm that the endpoint URL is spelled correctly and matches the API documentation.
- Make sure any path parameters (like id) are valid and exist in your system.
- Check whether the API version or environment (staging, production, etc.) is correct.
401 Unauthorized or 403 Forbidden
These errors indicate issues with authentication or permissions.
What to do:
- Ensure you’ve added the correct Authorization header or token.
- Check if your token has expired and request a new one if needed.
- Verify your user account has the necessary permissions for that endpoint.
500 Internal Server Error (and 5xx in general)
This is usually a server-side issue, but it’s good practice to confirm your request is valid.
What to do:
- Retry the request after a few minutes (it may be temporary).
- Validate your request payload and parameters against the schema again.
- If the error persists, contact the API provider with details of your request.
General Tips
- Use Postman’s console (View > Show Postman Console) to debug the exact request and response details.
- Compare your request with the examples provided in the API documentation.
- Save corrected requests in your collection for future testing.
Updated about 1 month ago
