API Reference
Errors

Errors

Handle API errors and understand standard error codes


Errors are raised under the related HTTP 4xx Client Error or 5xx Server Error HTTP status codes. The body of the response includes more information.

Error Response Format

{
  "details": {
    "payment_method_id": "Required"
  },
  "error_description": "payment_method_id",
  "error_type": "InvalidAttributes",
  "object": "error"
}
{
  "details": {
    "object": "list",
    "values": [
      {
        "email": "Required"
      },
      {
        "name": "Required"
      }
    ]
  },
  "error_description": "[0][email], [1][name]",
  "error_type": "InvalidAttributes",
  "object": "error"
}

Error Handling in SDKs

import payload
from payload.exceptions import InvalidAttributes, TransactionDeclined
 
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Handle errors when creating a payment
try:
    cust = pl.Account.get('your_customer_id')
    pl.Transaction.create(type='payment', sender={'account_id': cust.id}, amount=100)
except TransactionDeclined:
    print("Transaction declined")
except InvalidAttributes as e:
    print(e)

Catch and handle errors when API operations fail due to validation issues or missing resources.

import payload
from payload.exceptions import InvalidAttributes
 
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
 
# Handle errors when creating multiple customers
try:
    pl.Account.create(
        [
            pl.Account(type="customer", name="John Doe"),
            pl.Account(
                type="customer",
                name="John Doe",
                contact_details={'email': "[email protected]"},
            ),
        ]
    )
except InvalidAttributes as e:
    print(e)

When creating or updating multiple objects, errors are returned for each object with validation issues.

Standard Error Codes

Object Operation Validation Issues

CodeNameMeaning
400Bad RequestA bad request is most commonly a validation issue due to missing or malformed attributes. More information on the issue can be found in the body of the response.

Issues With Access & Permissions

CodeNameMeaning
401UnauthorizedAn unauthorized response is caused by an invalid or expired API secret key.
403ForbiddenA forbidden response is caused when a request is made to a resource that is not in scope of the API secret key that was used.

Requesting Nonexistent Resources

CodeNameMeaning
404Not FoundA not found response is used when requesting a URL path that does not exist. If the URL path is the full object resource path, the object has likely been deleted.

API Rate Limit Reached

CodeNameMeaning
429Too Many RequestsA too many requests response is raised when the API secret key, IP, or other limiting factor has reached the preset usage limit.

Internal Issues & Downtime

CodeNameMeaning
500Internal Server ErrorAn internal server error is raised if there was an unexpected issue while processing your request.
503Service UnavailableA service unavailable error is raised if the Payload service you're requesting has been temporarily brought offline for maintenance.