A step by step guide to making your first request with the Layer API
If you're new to working with APIs or just want a step-by-step orientation on how to make an API request with Layer, you're in the right place.
In this step-by-step guide, we'll walk you through the process of making a request to fetch all Categories associated with a specific Layer Project.
Prerequisites
- API Token: Ensure you have a valid bearer token for authentication. You can find your token in your Layer user dashboard here.
- Project ID: You'll need the ID of the project for which you want to retrieve categories. You can find your project ID by opening your layer project in a web browser and copying the project ID from the url. Our Introduction page includes a guide for finding your Project ID.
Step-by-Step Guide
Step 1: Set Up Your Environment
Before making the request, ensure you have a tool or environment ready to send HTTP requests. Some popular options include:
- Postman: A user-friendly tool for API testing. Layer has published a Postman Collection to make getting started with the Layer API easy
- cURL: A command-line tool for sending HTTP requests.
For this guide, we'll use cURL, but the process is similar for other tools.
Step 2: Construct the URL
The base URL for the endpoint is:
https://api.layer.team/projects/{PROJECT_ID}/categories
Replace {PROJECT_ID}
with the actual ID of your project. For example, if your project ID is 23rv09jbrgb0sdkan
, the URL becomes:
https://api.layer.team/projects/23rv09jbrgb0sdkan/categories
Step 3: Make the Request
Using cURL, construct, and execute the following command:
curl -X GET "https://api.layer.team/projects/23rv09jbrgb0sdkan/categories" \
-H "Authorization: Bearer {YOUR_API_TOKEN}"
Replace {YOUR_API_TOKEN}
with your bearer token.
Step 4: Review the Response
Upon executing the command, you should receive a JSON response containing a list of categories for the specified project. The response will look something like this:
{
"categories": [
{
"createdAt": "2023-08-01T12:00:00Z",
"count": 5,
"initials": "IS",
"instance": "Issue",
"modelCategory": true,
"order": 1,
"name": "Punch List",
"id": "2e03d9ev0erjkfg",
"updatedAt": "2023-08-02T12:00:00Z"
},
...
]
}
Each category in the list will have properties such as createdAt
, count
, initials
, instance
, modelCategory
, order
, name
, id
, and updatedAt
.
Step 5: Handle Errors
If there's an issue with your request, you might receive an error response.
Common issues include:
- Invalid bearer token. You can try clicking
Regenerate Token
in the Layer dashboard to create a new one. Review the Authentication Guide for more details - The project doesn't exist or is inaccessible
Conclusion
Congratulations! You've successfully made your first request to retrieve categories from a project using our API. As you become more familiar with the platform, you can explore other endpoints and functionalities to make the most out of your projects and data. If you encounter any issues or have further questions, don't hesitate to consult the official API documentation or reach out to [email protected].