Making Your First API Call
Step-by-step guide to making your first API request
A comprehensive guide to making your first API request, covering authentication, request construction, and response handling.
Request Basics
Learn the fundamental steps of constructing and sending an API request, including setting headers and handling responses.
Prerequisites
Before you start, ensure you have:
- An API key (see Account Setup)
- A tool for making HTTP requests (curl, Postman, or your preferred programming language)
- Basic understanding of JSON
Basic Request Structure
All API requests follow this general pattern:
- Base URL:
https://api.company.com/v1
- Authentication: API key in Authorization header
- Content-Type:
application/json
for requests with bodies - HTTP Method: GET, POST, PUT, DELETE depending on the operation
Sample Request: Text Analysis
Here's an example of analyzing text with our API:
python
import requests
api_key = "YOUR_API_KEY"
url = "https://api.company.com/v1/analyze"
headers = {
"Authorization": f"Api-Key {api_key}",
"Content-Type": "application/json"
}
data = {
"text": "Your text to analyze",
"features": ["sentiment", "entities", "keywords"]
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
print(f"Analysis results: {result}")
else:
print(f"Error: {response.status_code} - {response.text}")
Handling the Response
Successful responses have a 200 OK status and return JSON. Always check the status code before processing the response body. For error handling strategies, see our Error Handling Guide.
Testing in API Playground
Use our API Playground in the Developer Portal to test requests without writing code. It provides a visual interface for constructing requests and viewing responses.
Was this article helpful?
Need Personalized Assistance?
Our support team is ready to help you resolve any outstanding questions.