Skip to main content

CustomFieldsPublicApiRouter

Overview

Base Configuration

Environments

All requests should be directed to the following base URLs depending on the environment:

EnvironmentBase URL
Productionhttps://api.payments.ai/v1/public-api
Staginghttps://staging-api.payments.ai/v1/public-api

Authentication & Authorization

  • Authentication: Requires a valid API Key passed in the Authorization header.
  • Role Required: The API Key must belong to a user with the EDITOR role (or higher) in the target organization.

Endpoints

1. Create or Upsert Custom Field

Creates a new custom field definition or updates an existing one if it already matches the name and resource.

  • Method: POST
  • Route: /organizations/{organizationId}/custom-fields

Request Parameters

Path Parameters:

ParameterTypeRequiredDescription
organizationIdstringYesThe unique identifier (UUID) of the organization.

Body Parameters (JSON):

ParameterTypeRequiredConstraintsDescription
namestringYesMax 255 charsThe internal identifier name for the field.
resourcestringYesEnumThe resource to attach this field to.
Allowed values: customers, payment-instruments, plans, products, subscriptions, transactions, websites.
descriptionstringYesMax 255 charsA human-readable description of the field's purpose.
typeSchemaobjectYesValid Schema ObjectConfiguration defining the data type (string, number, boolean, etc.) and validation rules.

Type Schema Configuration

The typeSchema object requires a type property and an optional additionalSchema object. Supported types are: monetary, string, number, integer, datetime, date, boolean, array.

Example typeSchema structures:

  • String:
    {
    "type": "string",
    "additionalSchema": {
    "required": true,
    "maxLength": 100,
    "allowedValues": ["Value A", "Value B"]
    }
    }
  • Boolean:
    {
    "type": "boolean",
    "additionalSchema": {
    "default": false
    }
    }
  • Monetary:
    {
    "type": "monetary",
    "additionalSchema": {
    "default": { "currency": "USD", "amount": 0 }
    }
    }

Example Request

curl --location --request POST 'https://api.payments.ai/v1/public-api/organizations/{{ORGANIZATION_ID}}/custom-fields' \
--header 'Content-Type: application/json' \
--header 'Authorization: {{YOUR_API_KEY}}' \
--data '{
"name": "hideCustomerAddressOnInvoice",
"resource": "customers",
"description": "Hide customer address on invoice",
"typeSchema": {
"type": "boolean",
"additionalSchema": {
"required": false,
"default": false
}
}
}'


Example Response (201 Created)

{
"type": "object",
"data": {
"id": "cf_112233",
"organizationId": "6f326525-1586-479b-8176-55ba802caea4",
"name": "hideCustomerAddressOnInvoice",
"resource": "customers",
"description": "Hide customer address on invoice",
"typeSchema": {
"type": "boolean",
"additionalSchema": {
"required": false,
"default": false
}
},
"createdAt": "2023-11-01T12:00:00Z",
"updatedAt": "2023-11-01T12:00:00Z"
}
}



2. Retrieve Custom Field

Fetches the configuration details of a specific custom field definition based on its name and associated resource.

  • Method: GET
  • Route: /organizations/{organizationId}/custom-fields

Request Parameters

Path Parameters:

ParameterTypeRequiredDescription
organizationIdstringYesThe unique identifier (UUID) of the organization.

Query Parameters:

ParameterTypeRequiredConstraintsDescription
namestringYesMax 255 charsThe name of the custom field (e.g., customerInvoiceNotes).
resourcestringYesEnumThe resource type the field belongs to.

Allowed values: customers, payment-instruments, plans, products, subscriptions, transactions, websites. |

Example Request

curl --location --request GET 'https://api.payments.ai/v1/public-api/organizations/{{ORGANIZATION_ID}}/custom-fields?name=customerInvoiceNotes&resource=customers' \
--header 'Authorization: {{YOUR_API_KEY}}'

Example Response (200 OK)

{
"type": "object",
"data": {
"id": "cf_98765",
"organizationId": "6f326525-1586-479b-8176-55ba802caea4",
"name": "customerInvoiceNotes",
"resource": "customers",
"description": "Customer invoice notes",
"typeSchema": {
"type": "string",
"additionalSchema": {
"required": false,
"default": ""
}
},
"createdAt": "2023-10-27T10:00:00Z",
"updatedAt": "2023-10-27T10:00:00Z"
}
}



Error Handling

The API returns standard HTTP status codes to indicate the success or failure of requests.

Status CodeDescription
200 OKResource retrieved successfully.
201 CreatedCustom field created or updated successfully.
400 Bad RequestValidation failed (e.g., invalid resource type or schema mismatch).
401 UnauthorizedMissing or invalid API Key.
403 ForbiddenUser does not have permission to modify custom fields.
404 Not FoundCustom field not found (for GET requests).
500 Server ErrorInternal system error.

Example Error Response (400 Bad Request)

{
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"details": [
{
"field": "resource",
"message": "Invalid enum value. Expected 'customers' | 'transactions'..."
}
]
}