Quick Start Guide
This guide will help you get started with the Matik API quickly. We'll cover the basics of setting up your client, authenticating, and making your first API call to generate a presentation.
Prerequisites
Before you begin, make sure you have:
- A Matik account with API access
- Basic understanding of RESTful APIs and OAuth 2.0
Getting Started
Create a Client
To get started with the API, follow these steps:
- Reach out to your account manager to enable the Matik REST API in your account.
- Navigate to the enterprise settings page by clicking on your avatar in the upper right and selecting "Enterprise Settings".
- Click on the "Clients" tab on the enterprise settings page.
- Create a new client, copying the client secret to somewhere secure when you see it.
- Set the redirect URI to the location in your domain to complete the authorization.
Implement OAuth 2.0
Once you've set up the client in Matik, you can implement the OAuth 2.0 authorization flow:
- Redirect the user to the authorization URL:
const authUrl = 'https://app.matik.io/oauth/authorize' +
'?response_type=code' +
'&client_id=YOUR_CLIENT_ID' +
'&redirect_uri=YOUR_REDIRECT_URI' +
'&scope=producer+consumer' +
'&state=OPTIONAL_STATE_VALUE';
// Redirect user to authUrl
- After the user authorizes your application, they will be redirected to your redirect URI with an authorization code. Exchange this code for access and refresh tokens:
async function getTokens(code, clientId, clientSecret, redirectUri) {
try {
const response = await fetch('https://app.matik.io/api/v1/oauth/token/', {
method: 'POST',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
grant_type: 'authorization_code',
client_id: clientId,
client_secret: clientSecret,
redirect_uri: redirectUri,
code: code,
scope: 'producer consumer'
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// Store these tokens securely
const accessToken = data.access_token;
const refreshToken = data.refresh_token;
return { accessToken, refreshToken };
} catch (error) {
console.error('Error obtaining tokens:', error);
throw error;
}
}
- Once the access token expires, you can refresh it using the refresh token.
Generate a Presentation
With your access token, you can now generate a presentation:
async function generatePresentation(accessToken, templateId, inputs) {
try {
const response = await fetch('https://app.matik.io/api/1.0/presentations', {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "My Generated Presentation",
template_id: templateId,
inputs: inputs // Object containing input name/value pairs
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// The API returns the presentation ID and sets the Location header
const presentationId = data.id;
const statusUrl = response.headers.get('location');
return { presentationId, statusUrl };
} catch (error) {
console.error('Error generating presentation:', error);
throw error;
}
}
Check Presentation Status
Presentations are generated asynchronously. You need to poll the status endpoint:
async function checkPresentationStatus(accessToken, statusUrl) {
try {
const response = await fetch(statusUrl, {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
// Accept 200 (in progress) and 303 (completed)
if (response.status === 303) {
// Presentation is ready, get the presentation details URL
const presentationUrl = response.headers.get('location');
return { status: 'completed', presentationUrl };
} else if (response.status === 200) {
// Still processing
return { status: 'processing' };
} else {
throw new Error(`HTTP error! status: ${response.status}`);
}
} catch (error) {
console.error('Error checking presentation status:', error);
throw error;
}
}
Get Presentation Details
Once the presentation is ready, you can fetch its details:
async function getPresentationDetails(accessToken, presentationUrl) {
try {
const response = await fetch(presentationUrl, {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// Response includes download_url for PDF and other presentation details
return data;
} catch (error) {
console.error('Error getting presentation details:', error);
throw error;
}
}
Next Steps
Now that you've learned the basics, you can:
- Explore the API Reference for detailed endpoint documentation
- Learn about OAuth 2.0 Authorization for more advanced authentication scenarios
- Check out our Templates API to manage your presentation templates
For any questions or issues, please contact our support team at support@matik.io.
