Token
For every Prefetch Pageviews API call to get the count or increment it, you need to pass a JWT token. The token endpoint is what provides the JWT token.
About token
Point to note about token is its validity and why it matters.
- A valid token can be used to increment page count for any page
- A valid token can update a given page for a certain action only once within
15 minutes
window, subsequest request would succeed but wont change the count within the15 minutes
since last update - A token fetch request within the same time frame would return the same token
Token Expiration & Refreshing
A token is valid for 1 hour
. After this period, the token will expire, and you will need to request a new one. It’s a good practice to monitor the time of your token creation and refresh it proactively before it expires to avoid service interruptions.
Token Caching
To reduce the number of token fetch requests, you can implement token caching on your client or server-side. Since a token is valid for 1 hour, caching it locally until expiration can improve performance and reduce load on the /token
endpoint.
Token Management
To simplify the process of token management, including fetching, refreshing, and securely storing tokens, we recommend using our npm package. This package abstracts the complexity of token lifecycle management and helps you focus on the core functionality of your application.
Get Token
Request
curl -X GET "https://prefetch.io/api/v1/token"
Response
{
"token": "your-generated-token-string"
}
Request Headers
No special headers are required for this endpoint.
Response Body
If the request is successful, the API will return a JSON object containing the generated authentication token. This token is used to authenticate API requests and should be kept secure.
Example Response:
{
"token": "your-generated-token-string"
}
- token: A string containing the generated authentication token. This token is required for authenticating future API requests to Prefetch API.
Success Response
- Status Code: 200 OK
- The response body will contain the generated token, which can be used for authenticating API requests.
Error Responses
-
401 Unauthorized:
- The client is not authorized to generate a token, possibly due to missing credentials or lack of permissions.
-
500 Internal Server Error:
- An error occurred on the server while processing the request.