Skip to main content
All Safefy API responses follow a consistent format, making it easy to handle success and error cases.

Success format

{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "Pending",
    "amount": 1000
  },
  "message": "Transaction created successfully"
}

Error format

{
  "data": null,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "The 'amount' field must be greater than zero"
  }
}

HTTP status codes

CodeMeaning
200Success
201Resource created
400Validation error
401Not authenticated
403Not authorized
404Resource not found
409Conflict (e.g., duplicate externalId)
429Rate limit exceeded
500Internal server error

Error codes

CodeDescription
VALIDATION_ERRORInvalid or missing fields
AUTHENTICATION_REQUIREDToken not provided
INVALID_TOKENInvalid or expired token
FORBIDDENUnauthorized IP or insufficient permissions
NOT_FOUNDResource not found
DUPLICATE_EXTERNAL_IDexternalId already exists
INSUFFICIENT_BALANCEInsufficient balance for cashout
RATE_LIMIT_EXCEEDEDToo many requests
INTERNAL_ERRORInternal error

Handling errors

try {
  const response = await fetch('https://api-payment.safefypay.com.br/v1/transactions', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
  });
  
  const result = await response.json();
  
  if (result.error) {
    switch (result.error.code) {
      case 'VALIDATION_ERROR':
        console.error('Invalid data:', result.error.message);
        break;
      case 'INVALID_TOKEN':
        break;
      default:
        console.error('Error:', result.error.message);
    }
  } else {
    console.log('Transaction created:', result.data);
  }
} catch (error) {
  console.error('Network error:', error);
}

Rate limiting

When you exceed the request limit, the API returns 429 with the Retry-After header:
HTTP/1.1 429 Too Many Requests
Retry-After: 60
Content-Type: application/json

{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Request limit exceeded. Try again in 60 seconds."
  }
}
Use the Retry-After header to know when you can retry.