Merchant Authentication Guide
In order to interact securely with the SoyCap.io API, each merchant must authenticate to obtain an access token (auth_token
). This token is then used to authorize further API requests to obtain transaction details for creating campaigns, registering conversions, and distributing rewards. Below is a step-by-step guide to authenticate a merchant on your backend.
Step 1. Get Merchant API Key
You need the get merchant API key (api_key
) provided by SoyCap.io for your merchant account.
- Navigate to Merchant Dashboard
- Go to Dev Tools tab
- Click on Reveal Merchant API button
- The merchant
api_key
will be copied to your clipboard
Step 2. Make Authentication Request
The authentication process involves sending a request to the /api/merchants/authenticate
API endpoint using the api_key
in the X-API-Key
header:
import fetch from 'node-fetch';
const apiUrl = 'https://www.soycap.io/api'; // Replace with the actual API URLconst apiKey = 'api_key'; // Replace with your merchant API key
// Function to authenticate merchant and retrieve an auth tokenconst authenticateMerchant = async (apiUrl, apiKey) => { try { const response = await fetch(`${apiUrl}/merchants/authenticate`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey, // Custom header for API key }, });
// Check if the request was successful if (!response.ok) { const errorResponse = await response.json(); throw new Error(`Error: ${errorResponse.error} - ${errorResponse.message}`); }
// Extract and return the token from the response const data = await response.json(); return data.token;
} catch (err) { console.error('Failed to authenticate merchant:', err); throw err; }};
// Usage Example(async () => { try { const auth_token = await authenticateMerchant(apiUrl, apiKey); console.log('Authentication successful. Token:', auth_token); } catch (error) { console.error('Authentication failed:', error); }})();