Generate API Tokens
How to Generate API Tokens
Here's an example showing how to:
Create an AuthGrant
Generate an API token
Use the token to send a boost via the HTTP API
// Step 1: Create an AuthGrant with specific permissions
const grantId = await learnCard.invoke.addAuthGrant({
name: "Boost Sender Auth",
description: "Permission to send boosts",
scope: 'boosts:write',
});
// Step 2: Generate an API token from the AuthGrant
const token = await learnCard.invoke.getAPITokenForAuthGrant(grantId);
// Step 3: Prepare the payload for your API request
const payload = {
boostUri: "uri-of-the-boost-to-send",
signingAuthority: "your-signing-authority"
};
// Step 4: Make an authenticated HTTP request using the token
const response = await fetch(
`https://network.learncard.com/api/boost/send/via-signing-authority/RECIPIENT_PROFILE_ID`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify(payload),
}
);
// Step 5: Process the response
if (response.status === 200) {
const sentBoostUri = await response.json();
console.log(`Boost sent successfully: ${sentBoostUri}`);
} else {
console.error(`Error sending boost: ${response.status}`);
const errorDetails = await response.json();
console.error(errorDetails);
}
Managing API Tokens in LearnCardApp
Steps to Create an API Token
Navigate to Your Profile:
Go to Developer Tools > API Tokens.
Create an API Token:
Click: Create an API Token
Provide the Following Information:
Name (required)
Description (optional)
Scope (required)
Expiration (optional)
Click: Create
Already Signed In? Deep link below 👇 - LearnCardApp API Token Dev Tools
Token Management Features
Revoke/Delete a Token
Update an Existing Token
View Token Details: Including status, token, creation date, expiration, and scope.
Last updated
Was this helpful?