Wiki Navigation

API Authentication

All API requests to the DZconfig API require authentication. This page explains how to authenticate your requests.

API Tokens

Authentication is performed using API tokens. Each user has a unique API token that is used to identify and authorize their requests.

Finding Your API Token

Your API token can be found in your user profile. To access your API token:

  1. Log in to your DZconfig account
  2. Navigate to your profile settings
  3. Look for the "API Token" section
  4. Copy your API token

Important: Keep your API token secure. Do not share it with others or expose it in client-side code.

Using Your API Token

To authenticate your API requests, include your API token in the Authorization header of your HTTP requests using the Bearer token scheme:

Authorization: Bearer YOUR_API_TOKEN

Example with cURL

curl -X GET "https://dzconfig.com/api/user" \
     -H "Authorization: Bearer YOUR_API_TOKEN" \
     -H "Accept: application/json"

Example with JavaScript

fetch('https://dzconfig.com/api/user', {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer YOUR_API_TOKEN',
        'Accept': 'application/json'
    }
})
.then(response => response.json())
.then(data => {
    // Process the response data as needed
})
.catch(error => {
    // Handle errors appropriately
});

Example with PHP

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://dzconfig.com/api/user');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_TOKEN',
    'Accept: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
print_r($data);

Testing Authentication

You can test if your authentication is working correctly by making a request to the /api/validate endpoint:

curl -X GET "https://dzconfig.com/api/validate" \
     -H "Authorization: Bearer YOUR_API_TOKEN" \
     -H "Accept: application/json"

If your authentication is successful, you should receive a response with a 200 status code and a JSON object containing a success message:

Authentication Errors

If your authentication fails, you will receive a response with a 401 Unauthorized status code and an error message:

Common reasons for authentication failures include:

  • Invalid or expired API token
  • Missing Authorization header
  • Incorrect format of the Authorization header

Token Security

To keep your API token secure:

  • Never share your API token with others
  • Do not include your API token in client-side code
  • Use HTTPS for all API requests
  • Regenerate your API token if you suspect it has been compromised