Understand the basics of API authentication and how to protect your application with tokens.
Authentication is a critical aspect of interacting with the JustCMS Public API. To ensure secure access, all API requests must include a Bearer token in the headers. This article explains how to authenticate your requests, what happens if authentication fails, and how to handle common errors effectively.
To authenticate your requests to the JustCMS Public API, include the following header in every API call:
Authorization: Bearer YOUR_TOKEN
Replace YOUR_TOKEN
with your actual authentication token. The token ensures that only authorized users can access project data and resources. Without this token, the API will reject your requests.
Here is an example of a request with the required authentication header:
GET https://api.justcms.co/public/66d26d17-635e-4206-a1f2-560ae244e9f0
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5
Authentication issues can result in the following error responses:
403 Forbidden: This error occurs if the token is invalid, expired, or missing. Ensure that you provide a valid token with your requests.
404 Not Found: This error is returned when the requested resource or project does not exist. Verify the endpoint URL and resource identifiers (e.g., project ID).
If you encounter authentication errors, follow these steps to resolve them:
Verify the Token: Ensure that the token included in the Authorization
header is correct and has not expired.
Request a New Token: If your token has expired, request a new one from your account or API client.
Check Permissions: Confirm that the token has the necessary permissions to access the requested resource.