Complyance Logo

Authentication

Learn how to authenticate with the Complyance API using API keys and JWT tokens.

API Keys

API keys are the primary method of authentication for the Complyance API.

Getting Your API Key

  1. Sign up for a Complyance account
  2. Navigate to the API section in your dashboard
  3. Generate a new API key
  4. Copy the key for use in your application

Using API Keys

Include your API key in the Authorization header:

curl -H "Authorization: Bearer YOUR_API_KEY" \
     https://api.complyance.io/v1/invoices

SDK Usage

// Java SDK
SDKConfig config = new SDKConfig(
    "your-api-key",
    Environment.SANDBOX,
    "your-app-id"
);
GETSUnifySDK.configure(config);
# Python SDK
import complyance

client = complyance.Client(
    api_key="your-api-key",
    environment="sandbox"
)
// Node.js SDK
const complyance = require('@complyance/sdk');

const client = new complyance.Client({
    apiKey: 'your-api-key',
    environment: 'sandbox'
});

JWT Tokens

For enhanced security, you can use JWT tokens instead of API keys.

Generating JWT Tokens

curl -X POST https://api.complyance.io/v1/auth/token \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "YOUR_API_KEY",
    "expiresIn": 3600
  }'

Using JWT Tokens

curl -H "Authorization: Bearer JWT_TOKEN" \
     https://api.complyance.io/v1/invoices

Environment Configuration

Sandbox Environment

Use the sandbox environment for testing:

SDKConfig config = new SDKConfig(
    "your-sandbox-api-key",
    Environment.SANDBOX,
    "your-app-id"
);

Production Environment

Switch to production when ready:

SDKConfig config = new SDKConfig(
    "your-production-api-key",
    Environment.PRODUCTION,
    "your-app-id"
);

Security Best Practices

API Key Management

  • Never commit API keys to version control
  • Use environment variables for API keys
  • Rotate keys regularly
  • Use different keys for different environments

Environment Variables

# .env file
COMPLYANCE_API_KEY=your-api-key
COMPLYANCE_APP_ID=your-app-id
COMPLYANCE_ENVIRONMENT=sandbox

Code Example

public class ApiConfig {
    private static final String API_KEY = System.getenv("COMPLYANCE_API_KEY");
    private static final String APP_ID = System.getenv("COMPLYANCE_APP_ID");
    private static final Environment ENV = Environment.valueOf(
        System.getenv("COMPLYANCE_ENVIRONMENT")
    );
    
    public static SDKConfig getConfig() {
        return new SDKConfig(API_KEY, ENV, APP_ID);
    }
}

Error Handling

Authentication Errors

The API returns specific error codes for authentication issues:

{
  "status": "ERROR",
  "message": "Authentication failed",
  "errors": [
    {
      "code": "INVALID_API_KEY",
      "message": "The provided API key is invalid"
    }
  ]
}

Common Error Codes

  • INVALID_API_KEY: API key is invalid or expired
  • MISSING_API_KEY: No API key provided
  • INSUFFICIENT_PERMISSIONS: API key lacks required permissions
  • RATE_LIMIT_EXCEEDED: Too many requests

Handling Errors

try {
    UnifyResponse response = GETSUnifySDK.pushToUnify(
        appId, documentType, country, operation, mode, purpose, payload
    );
} catch (SDKException e) {
    if (e.getCode().equals("INVALID_API_KEY")) {
        // Handle invalid API key
        System.err.println("Please check your API key");
    } else if (e.getCode().equals("RATE_LIMIT_EXCEEDED")) {
        // Handle rate limit
        System.err.println("Rate limit exceeded, please wait");
    }
}

Testing Authentication

Verify API Key

curl -H "Authorization: Bearer YOUR_API_KEY" \
     https://api.complyance.io/v1/auth/verify

Test Connection

public class AuthTest {
    public static void main(String[] args) {
        try {
            SDKConfig config = new SDKConfig(
                "your-api-key",
                Environment.SANDBOX,
                "your-app-id"
            );
            GETSUnifySDK.configure(config);
            
            // Test with a simple request
            Map<String, Object> testPayload = Map.of("test", true);
            UnifyResponse response = GETSUnifySDK.pushToUnify(
                "your-app-id",
                DocumentType.TAX_INVOICE,
                "SA",
                Operation.SINGLE,
                Mode.DOCUMENTS,
                Purpose.MAPPING,
                testPayload
            );
            
            System.out.println("Authentication successful!");
            
        } catch (Exception e) {
            System.err.println("āŒ Authentication failed: " + e.getMessage());
        }
    }
}

Next Steps