Skip to main content

Proxies

Proxies provide a way to pre-configure static routes when calling Basis Theory's Proxy. They require you to set a destination URL for where the request will be forwarded to, require authentication to call the proxy, and configure a Reactor which can be executed as part of the request to transform the request body and headers.

Proxies can be utilized for both inbound and outbound calls for things such as webhooks, enabling 3rd parties to call your API or making API calls to 3rd party partners and providers.

Create a Proxy

Creates a new Proxy for the Tenant.

POST https://api.basistheory.com/proxies
Copy

Permissions

proxy:create

Request

curl "https://api.basistheory.com/proxies" \
-H "BT-API-KEY: key_N88mVGsp3sCXkykyN2EFED" \
-H "Content-Type: application/json" \
-X "POST" \
-d '{
"name": "My Proxy",
"destination_url": "https://example.com/api",
"request_transform": {
"code": "
module.exports = async function (req) {
// Do something with `req.configuration.SERVICE_API_KEY`

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"response_transform": {
"code": "
module.exports = async function (req) {
// Do something with `req.configuration.SERVICE_API_KEY`

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"configuration": {
"SERVICE_API_KEY": "key_abcd1234"
},
"application": {
"id": "45c124e7-6ab2-4899-b4d9-1388b0ba9d04"
},
"require_auth": true
}'

Request Parameters

AttributeRequiredTypeDefaultDescription
nametruestringnullThe name of the Proxy. Has a maximum length of 200
destination_urltruestringnullThe URL to proxy requests to
request_transformfalseProxy TransformnullTransform code which will be executed against the proxy's request before sending to the destination.
response_transformfalseProxy TransformnullTransform code which will be executed against the destination's response before returning the proxy response.
applicationfalseApplicationnullThis Application's API key is injected into a pre-configured Node.js BasisTheory instance passed into the Proxy Transform runtime.
configurationfalsemapnullA key-value map of all configuration name and values for a Proxy Transform
require_authfalsebooleantrueRequire a BT-API-KEY request header for authentication and authorization

Response

Returns a Proxy if the Proxy was created. Returns an error if there were validation errors, or the Proxy failed to create.

{
"id": "433013a6-a614-4e1e-b2aa-5fba67aa85e6",
"tenant_id": "77cb0024-123e-41a8-8ff8-a3d5a0fa8a08",
"name": "My Proxy",
"key": "e29a50980ca5",
"destination_url": "https://example.com/api",
"request_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"response_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"configuration": {
"SERVICE_API_KEY": "key_abcd1234"
},
"application_id": "45c124e7-6ab2-4899-b4d9-1388b0ba9d04",
"require_auth": true,
"created_by": "3ce0dceb-fd0b-4471-8006-c51243c9ef7a",
"created_at": "2020-09-15T15:53:00+00:00"
}

List Proxies

Get a list of proxies for the Tenant.

GET https://api.basistheory.com/proxies
Copy

Permissions

proxy:read

Request

curl "https://api.basistheory.com/proxies" \
-H "BT-API-KEY: key_N88mVGsp3sCXkykyN2EFED"

Query Parameters

ParameterRequiredTypeDefaultDescription
idfalsearray[]An optional list of Proxy ID's to filter the list of proxies by
namefalsestringnullWildcard search of proxies by name

Response

Returns a paginated object with the data property containing an array of proxies. Providing any query parameters will filter the results. Returns an error if proxies could not be retrieved.

{
"pagination": {...}
"data": [
{
"id": "433013a6-a614-4e1e-b2aa-5fba67aa85e6",
"tenant_id": "77cb0024-123e-41a8-8ff8-a3d5a0fa8a08",
"name": "My Proxy",
"key": "e29a50980ca5",
"destination_url": "https://example.com/api",
"request_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"response_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"configuration": {
"SERVICE_API_KEY": "key_abcd1234"
},
"application_id": "45c124e7-6ab2-4899-b4d9-1388b0ba9d04",
"require_auth": true,
"created_by": "fb124bba-f90d-45f0-9a59-5edca27b3b4a",
"created_at": "2020-09-15T15:53:00+00:00",
"modified_by": "fb124bba-f90d-45f0-9a59-5edca27b3b4a",
"modified_at": "2021-03-01T08:23:14+00:00"
},
{...},
{...}
]
}

Get a Proxy

Get a Proxy by ID in the Tenant.

GET https://api.basistheory.com/proxies/{id}
Copy

Permissions

proxy:read

Request

curl "https://api.basistheory.com/proxies/5b493235-6917-4307-906a-2cd6f1a90b13" \
-H "BT-API-KEY: key_N88mVGsp3sCXkykyN2EFED"

URI Parameters

ParameterRequiredTypeDefaultDescription
idtrueuuidnullThe ID of the proxy

Response

Returns a Proxy with the id provided. Returns an error if the Proxy could not be retrieved.

{
"id": "433013a6-a614-4e1e-b2aa-5fba67aa85e6",
"tenant_id": "77cb0024-123e-41a8-8ff8-a3d5a0fa8a08",
"name": "My Proxy",
"key": "e29a50980ca5",
"destination_url": "https://example.com/api",
"request_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"response_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"configuration": {
"SERVICE_API_KEY": "key_abcd1234"
},
"application_id": "45c124e7-6ab2-4899-b4d9-1388b0ba9d04",
"require_auth": true,
"created_by": "fb124bba-f90d-45f0-9a59-5edca27b3b4a",
"created_at": "2020-09-15T15:53:00+00:00",
"modified_by": "fb124bba-f90d-45f0-9a59-5edca27b3b4a",
"modified_at": "2021-03-01T08:23:14+00:00"
}

Update Proxy

Update a Proxy by ID in the Tenant.

PUT https://api.basistheory.com/proxies/{id}
Copy

Permissions

proxy:update

Request

curl "https://api.basistheory.com/proxies/433013a6-a614-4e1e-b2aa-5fba67aa85e6" \
-H "BT-API-KEY: key_N88mVGsp3sCXkykyN2EFED" \
-H "Content-Type: application/json" \
-X "PUT" \
-d '{
"name": "My Proxy",
"destination_url": "https://example.com/api",
"request_transform": {
"code": "
module.exports = async function (req) {
// Do something with `req.configuration.SERVICE_API_KEY`

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"response_transform": {
"code": "
module.exports = async function (req) {
// Do something with `req.configuration.SERVICE_API_KEY`

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"configuration": {
"SERVICE_API_KEY": "key_abcd1234"
},
"application": {
"id": "45c124e7-6ab2-4899-b4d9-1388b0ba9d04"
},
"require_auth": true
}'

URI Parameters

ParameterRequiredTypeDefaultDescription
idtrueuuidnullThe ID of the proxy

Request Parameters

AttributeRequiredTypeDefaultDescription
nametruestringnullThe name of the Proxy. Has a maximum length of 200
destination_urltruestringnullThe URL to proxy requests to
request_transformfalseProxy TransformnullTransform code which will be executed against the proxy's request before sending to the destination.
response_transformfalseProxy TransformnullTransform code which will be executed against the destination's response before returning the proxy response.
applicationfalseApplicationnullThis Application's API key is injected into a pre-configured Node.js BasisTheory instance passed into the Proxy Transform runtime.
configurationfalsemapnullA key-value map of all configuration name and values for a Proxy Transform
require_authfalsebooleantrueRequire a BT-API-KEY request header for authentication and authorization

Response

Returns a Proxy if the Proxy was updated. Returns an error if there were validation errors, or the Proxy failed to update.

{

"id": "433013a6-a614-4e1e-b2aa-5fba67aa85e6",
"tenant_id": "77cb0024-123e-41a8-8ff8-a3d5a0fa8a08",
"name": "My Proxy",
"key": "e29a50980ca5",
"destination_url": "https://example.com/api",
"request_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"response_transform": {
"code": "
module.exports = async function (req) {
// Do something with req.configuration.SERVICE_API_KEY

return {
headers: req.args.headers,
body: req.args.body
};
};
"
},
"configuration": {
"SERVICE_API_KEY": "key_abcd1234"
},
"application_id": "45c124e7-6ab2-4899-b4d9-1388b0ba9d04",
"require_auth": true,
"created_by": "3ce0dceb-fd0b-4471-8006-c51243c9ef7a",
"created_at": "2020-09-15T15:53:00+00:00",
"modified_by": "34053374-d721-43d8-921c-5ee1d337ef21",
"modified_at": "2021-03-01T08:23:14+00:00"
}

Delete Proxy

Delete a Proxy by ID in the Tenant.

DELETE https://api.basistheory.com/proxies/{id}
Copy

Permissions

proxy:delete

Request

curl "https://api.basistheory.com/proxies/433013a6-a614-4e1e-b2aa-5fba67aa85e6" \
-H "BT-API-KEY: key_N88mVGsp3sCXkykyN2EFED" \
-X "DELETE"

URI Parameters

ParameterRequiredTypeDefaultDescription
idtrueuuidnullThe ID of the proxy

Response

Returns an error if the Proxy failed to delete.

Proxy Object

AttributeTypeDescription
iduuidUnique identifier of the Proxy which can be used to get a Proxy
keystringAuto-generated key used to invoke a particular Proxy
namestringThe name of the Proxy
destination_urlstringThe URL to proxy requests to
tenant_iduuidThe Tenant ID which owns the Proxy
require_authbooleanRequire a BT-API-KEY request header for authentication and authorization
request_transformProxy Transform(Optional) Transform code which will be executed against the proxy's request before sending to the destination.
response_transformProxy Transform(Optional) Transform code which will be executed against the destination's response before returning the proxy response.
application_idstring(Optional) This Application's API key is injected into a pre-configured Node.js BasisTheory instance passed into the Proxy Transform runtime.
configurationmap(Optional) A key-value map of all configuration name and values for a Proxy Transform
created_byuuid(Optional) The ID of the user or Application that created the Proxy
created_atstring(Optional) Created date of the Proxy in ISO 8601 format
modified_byuuid(Optional) The ID of the user or Application that last modified the Proxy
modified_atdate(Optional) Last modified date of the Proxy in ISO 8601 format

Proxy Transform Object

AttributeTypeDescription
codestringTransform code which will be executed when the Proxy transform is processed

Transform Code

All transform code snippets must export a function which takes in a request object and returns a response object.

Transform Request Object

This is the object passed as a parameter to the transform function.

AttributeTypeDescription
argsobjectThe arguments containing the body and headers attributes
configurationobjectThe configuration defined for the Proxy object
btobjectA pre-configured Basis Theory JS instance if an application was configured on the Proxy object

Transform Response Object

This is the object that must be returned by the transform function.

AttributeTypeDescription
bodyobjectProcessed body for the proxy request/response
headersobjectProcessed headers for the proxy request/response

Transform Code is written in Javascript (targeting Node.js v16) and generally follows the structure:

module.exports = async function (req) {
const { bt, args } = req;
const { body, headers } = args; // access any args provided with the transform request
const { MY_CONFIG } = req.configuration; // access any static config defined on the Proxy

// do anything here!
const processedBody = ...; // do something with body
const processedHeaders = ...; // do something with headers

return {
body: processedBody, // Proxy request/response body
headers: processedHeaders // Proxy request/response headers
};
};