Skip to main content
Skip table of contents

Tracking orders using nodejs + axios

The example below demonstrates triggering the association service using NodeJS and axios (https://axios-http.com) HTTP library:

JS
const axios = require('axios');

// Your API key with Order Tracking permissions
const apiKey = 'your_api_key_here';

// Sample order-to-recipe associations
const associations = [
    {
        "recipeId": "DRIVE-001",
        "orderNumber": "1001",
        "orderId": "1111111111111",
        "itemId": "2222222222222",
        "itemQuantity": 2
    },
    {
        "recipeId": "DRIVE-002",
        "orderNumber": "1001",
        "orderId": "1111111111111",
        "itemId": "3333333333333",
        "itemQuantity": 1
    }
];

// Option 1: Using Authorization header
axios.post(
    'https://api.customizer.drivecommerce.com/api/v2/recipe/order',
    associations,
    {
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${apiKey}`
        }
    }
)
.then(response => console.log('Success:', response.data))
.catch(error => console.error('Error:', error.response?.data || error.message));

// Option 2: Using apikey as query parameter
axios.post(
    `https://api.customizer.drivecommerce.com/api/v2/recipe/order?apikey=${apiKey}`,
    associations,
    {
        headers: {
            'Content-Type': 'application/json'
        }
    }
)
.then(response => console.log('Success:', response.data))
.catch(error => console.error('Error:', error.response?.data || error.message));
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.