API Tutorial

Step 2: Making Your First API Call

Now that your configuration is set up, let's make your first authenticated API request.

Using the API Client


// Example GET request
async function fetchUserData() {
    try {
        const response = await fetch('${config.API_URL}/v1/users', {
            method: 'GET',
            headers: {
                'Authorization': `Bearer ${config.API_KEY}`,
                'Content-Type': 'application/json'
            }
        });

        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }

        const data = await response.json();
        console.log('User Data:', data);
        return data;
    } catch (error) {
        console.error('Request failed:', error);
        throw error;
    }
}