πŸ”‘API Key

Learn how to access your Swapped Pay API Key, which is required when creating payments and interacting with Swapped Pay endpoints.

Get your API Key

To retrieve your API Key, visit the Developers section of the Swapped Pay dashboard. There, you can generate and view your API Key, which is required for specific Swapped Pay endpoints.

Using your API Key

  • For the Swapped Pay Widget, include the API Key in your iFrame URL. This means loading the iFrame with ?apiKey=<API_KEY> , for example:

    <iframe src="pay.swapped.com/SP-111111222222?apiKey=<API_KEY>"

  • When using your API Key to make requests to the Swapped Pay API directly, you'll need to sign your API Key in a specific way. Set this as the X-API-Key Header, as seen below:

const axios = require('axios');

// Config
const API_KEY  = 'YOUR_API_KEY';
const BASE_URL = 'https://pay-api.swapped.com';
const ENDPOINT = '/v1/orders';

// Payload
const payload = {
  purchase: {
    name: 'text',
    description: 'text',
    imageUrl: 'text',
    price: 'text',
    currency: 'USD'
  },
  metadata: {
    externalId: 'text',
    userId: 'text',
    userCountry: 'text',
    userEmail: 'text',
    redirectUrl: 'text'
  }
};

// Headers
const headers = {
  'X-API-Key': API_KEY,
  'Content-Type': 'application/json',
  'Accept': '*/*'
};

// Request
axios.post(`${BASE_URL}${ENDPOINT}`, payload, { headers })
  .then(response => {
    console.log('βœ… Success:', response.status);
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

Last updated