AuthenticationAPI Basics

Getting Started with the Sayswitch API

Quick Setup

Get started with API testing by creating a free Sayswitch account and obtaining your test keys. The Sayswitch API provides the same capabilities you find on your dashboard, making it easy to integrate them into your applications via RESTful methods.

Request Authorization Header

To ensure the authenticity of API requests, all requests must include the Authorization header with a Bearer Token containing your live or test secret key.

Authorization: Bearer {{ secret_key }}

⚠️

secret key must be in env file

HTTP Methods

MethodDescription
POSTUsed to create new resources
GETUsed to retrieve resources
PUTUsed to update existing resources
DELETEUsed to remove resources

Sample Requests

We provide sample API calls next to each method using cURL. All you need to do is insert your specific parameters, and you can test the calls from the command line. See this tutorial on using cURL with APIs.

Requests and Responses

Both request body data and response data are formatted as JSON. Content type for responses will always be application/json. Generally, all responses will be in the following format:

Response Keys

KeyTypeDescription
successBooleanIndicates whether your request was successful. It’s recommended to use this alongside HTTP status codes to determine the outcome of an API call.
messageStringA brief summary of the response status. For example, when retrieving customers, this might be “Customers retrieved”. In error cases, it describes the issue (e.g., missing authorization header). This is the only universal key across all responses.
dataObjectContains the result of the request. This could be a single object or an array depending on the request type. For instance, a single customer object for one record or an array of customers for a list request.

HTTP Status Codes

SaySwitch uses conventional HTTP response codes to indicate the success or failure of API requests. Here’s what each code means in the context of SaySwitch operations:

Success Codes

HTTP Status CodeMeaningSaySwitch Context
200OKThe request was successful. This is returned for most successful GET requests.
201CreatedThe request was successful and a resource was created. Returned for successful POST requests like creating transactions or customers.
202AcceptedThe request has been accepted for processing. Commonly returned when a payment is still being processed but has been queued successfully.
204No ContentThe request was successful, but there is no content to return. Typically returned for successful DELETE operations.

Client Error Codes

HTTP Status CodeMeaningSaySwitch Context
400Bad RequestThe request was malformed or had invalid parameters. For example, creating a transaction with an invalid amount or currency.
401UnauthorizedNo valid API key was provided, or the key used is incorrect. Check that you’re using the correct secret key.
403ForbiddenThe API key doesn’t have permission to perform the request. This can occur if you’re using a test key for a live endpoint or accessing features outside your account tier.
404Not FoundThe requested resource doesn’t exist. For example, trying to retrieve a transaction with an invalid ID.
405Method Not AllowedThe HTTP method used is not valid for the endpoint. For instance, trying to DELETE a transaction when only GET, POST, and PUT are allowed.
409ConflictThe request conflicts with the current state. For example, trying to create a duplicate unique resource like a customer with an existing email.
415Unsupported Media TypeThe request content type is not supported. Ensure you are sending JSON data with the correct Content-Type header.
422Unprocessable EntityThe request data was valid, but the server couldn’t process it. Often occurs when a transaction is declined due to issues like insufficient funds or fraud detection.
429Too Many RequestsYou’ve exceeded the API rate limits. Slow down and implement exponential backoff retry strategies.

Server Error Codes

HTTP Status CodeMeaningSaySwitch Context
500Internal Server ErrorSomething went wrong on SaySwitch end. Retry your request after a short delay and contact support if the issue persists.
502Bad GatewaySaySwitch is down or undergoing maintenance. Try again later.
503Service UnavailableThe SaySwitch servers are up, but currently overloaded with requests. Try again later.
504Gateway TimeoutThe SaySwitch servers didn’t respond in time. Try again later and check our status page for any ongoing issues.