Orders API Reference
Overview
The Orders API facilitates the management of customer purchases and access permissions for products on your platform. It supports creating, retrieving, updating, and canceling orders, with different types of orders available to suit various business needs.
Make sure you generated the api_token on your store. More info in the API Authentication guide
Order Types Overview
There are three types of orders you can create via the API:
Order Type | Description | Payment | Status |
---|---|---|---|
Permission | Grant access to a product or plan without generating a sales record | No payment gateway involved | Immediately approved |
Report | Record an external transaction (e.g., POS sale) in Publica.la | Bypasses payment gateway (payment assumed complete) | Immediately approved |
Sale | Initiate a standard checkout process through an integrated payment gateway | Payment required through gateway | Starts as pending , transitions to approved upon payment |
Endpoint Reference
Endpoint | Method | Description |
---|---|---|
/integration-api/v1/orders | POST | Create a new order |
/integration-api/v1/orders | GET | List or search for orders |
/integration-api/v1/orders/(id_or_external_ref) | GET | Retrieve a specific order |
/integration-api/v1/orders/(id_or_external_ref) | PUT | Update an existing order |
/integration-api/v1/orders/(id_or_external_ref) | DELETE | Cancel an order |
Create an Order
Create a new order of type permission
, report
, or sale
.
Endpoint: POST /integration-api/v1/orders
Automatic Resource Creation
- Users: If the
user.id
provided doesn't exist, a new user will be created automatically using the provideduser.id
anduser.email
- Products: For
sale
orders, if a product doesn't exist, it will be created automatically ifproducts.*.name
andproducts.*.url
are provided
Common Request Body Fields
Field | Type | Description | Required |
---|---|---|---|
type | string | Order type: permission , report , or sale | Yes |
external_reference | string | Your unique identifier for this order (max 64 chars) | No |
user | object | User information | Yes |
user.id | string | User unique ID in your system (max 64 chars) | Yes |
user.email | string | User's email address | Yes |
products | array | Array of products included in the order | Yes |
products.*.type | string | Product type: content or subscription | Yes |
products.*.id | string | Product unique ID in your system (max 64 chars) | Yes |
products.*.expiration_date | string | Optional: Date when user access expires (YYYY-MM-DD) | No |
Type-Specific Request Fields
- Permission
- Report
- Sale
Additional fields for Permission orders:
Field | Type | Description | Required |
---|---|---|---|
unit_price | float | Not typically used, but can be set | No |
currency_id | string | Not typically used, but can be set (ISO 4217 code) | No |
products.*.name | string | Product name (not required for permission orders) | No |
products.*.url | string | Product URL (not required for permission orders) | No |
products.*.unit_price | float | Product price (not typically used) | No |
products.*.currency_id | string | Product currency (not typically used) | No |
Example Request (Permission)
{
"type": "permission",
"external_reference": "GRANT-ACCESS-001",
"user": {
"id": "user-ext-123",
"email": "[email protected]"
},
"products": [
{
"id": "SUB-MONTHLY",
"type": "subscription"
},
{
"id": "BOOK-XYZ",
"type": "content",
"expiration_date": "2024-12-31"
}
]
}
Additional fields for Report orders:
Field | Type | Description | Required |
---|---|---|---|
return_url | string | URL for redirection (informational) | Yes |
unit_price | float | Total order price | Yes |
currency_id | string | Order currency (ISO 4217 code) | Yes |
products.*.name | string | Product name (required for product auto-creation) | Conditional |
products.*.url | string | Product URL (required for product auto-creation) | Conditional |
products.*.unit_price | float | Product price | Yes |
products.*.currency_id | string | Product currency (ISO 4217 code) | Yes |
Example Request (Report)
{
"type": "report",
"external_reference": "POS-SALE-456",
"return_url": "https://{store_final_domain}/order/receipt/POS-SALE-456",
"unit_price": 25.00,
"currency_id": "ARS",
"user": {
"id": "user-ext-456",
"email": "[email protected]"
},
"products": [
{
"id": "product-ext-002",
"type": "content",
"name": "External Product 2",
"url": "https://example.com/product/002",
"unit_price": 25.00,
"currency_id": "ARS"
}
]
}
Additional fields for Sale orders:
Field | Type | Description | Required |
---|---|---|---|
return_url | string | URL to redirect user after gateway interaction | Yes |
unit_price | float | Total order price | Yes |
currency_id | string | Order currency (ISO 4217 code) | Yes |
products.*.name | string | Product name (required for product auto-creation) | Conditional |
products.*.url | string | Product URL (required for product auto-creation) | Conditional |
products.*.unit_price | float | Product price | Yes |
products.*.currency_id | string | Product currency (ISO 4217 code) | Yes |
Completing the Checkout:
When creating a sale
order, the response includes a checkout.url
and checkout.expires_on
. You must redirect your user to the checkout.url
to complete the payment process.
The cancellation URL for orders can be configured in your store's dashboard under Settings > Integrations (/dashboard/settings#integrations
).
Example Request (Sale)
{
"type": "sale",
"external_reference": "WEB-ORDER-789",
"return_url": "https://{store_final_domain}/order/confirmation",
"unit_price": 15.50,
"currency_id": "ARS",
"user": {
"id": "user-ext-789",
"email": "[email protected]"
},
"products": [
{
"id": "product-ext-003",
"type": "content",
"name": "Online Course Access",
"url": "https://example.com/product/003",
"unit_price": 15.50,
"currency_id": "ARS"
}
]
}
Response (Create)
A successful creation returns 201 Created
with the following fields:
Field | Type | Description |
---|---|---|
id | string | Publica.la's unique order ID (UUID) |
external_reference | string | Your unique ID, if provided in the request |
type | string | The order type (permission , report , sale ) |
unit_price | float | Order price |
currency_id | string | Order currency |
status | string | Order status (approved , pending ) |
created_at | string | Creation date (YYYY-MM-DD) |
user | object | User information |
products | array | Array of products with status and details |
checkout | object | For sale orders with pending status only: URL and expiration for payment |
Example Response (Permission - Approved)
{
"data": {
"id": "03033649-de10-404b-aa8a-8682871001c2",
"external_reference": "GRANT-ACCESS-001",
"type": "permission",
"unit_price": 0,
"currency_id": null,
"status": "approved",
"created_at": "2024-07-29",
"user": {
"id": "user-ext-123",
"email": "[email protected]"
},
"products": [
{
"id": "SUB-MONTHLY",
"type": "subscription",
"name": "Monthly Subscription",
"status": "approved",
"expiration_date": null,
"cover": "https://cdn.publica.la/plan/cover.jpg",
"reader_url": null,
"description": null,
"pages_quantity": null,
"file_type": null,
"is_free": false,
"unit_price": 0
},
{
"id": "BOOK-XYZ",
"type": "content",
"name": "The Great Book",
"status": "approved",
"expiration_date": "2024-12-31",
"cover": "https://cdn.publica.la/item/12345.jpg",
"reader_url": "https://{store_final_domain}/reader/the-great-book",
"description": "An amazing story.",
"pages_quantity": 300,
"file_type": "epub",
"is_free": false,
"unit_price": 0
}
]
}
}
Example Response (Sale - Pending)
{
"data": {
"id": "a4b5c6d7-e8f9-4a0b-bc1d-e2f3a4b5c6d7",
"external_reference": "WEB-ORDER-789",
"checkout": {
"url": "https://{store_final_domain}/auth/token?external-auth-token={AUTH-TOKEN}",
"expires_on" : "2024-07-29 14:30:00"
},
"type": "sale",
"unit_price": 15.50,
"currency_id": "ARS",
"status": "pending",
"created_at": "2024-07-29",
"user": {
"id": "user-ext-789",
"email": "[email protected]"
},
"products": [
{
"id": "product-ext-003",
"type": "content",
"name": "Online Course Access",
"status": "pending",
"cover": "https://example.publica.la/images/cover-image-03.png",
"reader_url": "https://{store_final_domain}/reader/online-course-access",
"description": "Access to the online course.",
"pages_quantity": null,
"file_type": "external_link",
"is_free": false,
"unit_price": 15.50,
"currency_id": "ARS"
}
]
}
}
Response Codes
Code | Description |
---|---|
201 | Order created successfully |
422 | Validation error (details in response) |
401 | Unauthorized (invalid API token) |
Get Orders
Retrieve one or more orders.
Endpoints:
GET /integration-api/v1/orders
(list all orders, paginated)GET /integration-api/v1/orders/(id_or_external_ref)
(get specific order)
Query Parameters
Parameter | Type | Description | Required | Example |
---|---|---|---|---|
id_type | string | When getting specific order: internal or external | Yes | ?id_type=internal |
user_id | string | Filter by user ID | No | ?user_id=user-ext-123 |
user_email | string | Filter by user email | No | [email protected] |
product_id | string | Filter by product ID | No | ?product_id=product-123 |
product_type | string | Required if product_id is used | Conditional | ?product_type=content |
start_at | string | Filter by creation date, from (YYYY-MM-DD) | No | ?start_at=2024-01-01 |
end_at | string | Filter by creation date, to (YYYY-MM-DD) | No | ?end_at=2024-07-31 |
Example Requests
- Get by internal ID:
GET /integration-api/v1/orders/03033649-de10-404b-aa8a-8682871001c2?id_type=internal
- Get by external reference:
GET /integration-api/v1/orders/WEB-ORDER-789?id_type=external
- List by product:
GET /integration-api/v1/orders?product_id=product-ext-003&product_type=content
- List by date range:
GET /integration-api/v1/orders?start_at=2024-07-01&end_at=2024-07-31
Response
The response format is the same as the Create response, with pagination metadata when listing multiple orders.
Example Response (List Orders)
{
"data": [
{
"id": "c9f2b7b0-dc74-4c58-92a7-9dfcf93aed38",
"external_reference": "123-abc",
"unit_price": 17,
"currency_id": "USD",
// ... other fields ...
},
{
"id": "a4b5c6d7-e8f9-4a0b-bc1d-e2f3a4b5c6d7",
"external_reference": "WEB-ORDER-789",
// ... other fields ...
}
],
"links": {
"first": "https://{store_final_domain}/integration-api/v1/orders?page=1",
"last": "https://{store_final_domain}/integration-api/v1/orders?page=5",
"prev": null,
"next": "https://{store_final_domain}/integration-api/v1/orders?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 5,
"path": "https://{store_final_domain}/integration-api/v1/orders",
"per_page": 15,
"to": 15,
"total": 70
}
}
Response Codes
Code | Description |
---|---|
200 | Success |
404 | Order not found |
401 | Unauthorized (invalid API token) |
Update an Order
Update an existing order's status or expiration date.
Endpoint: PUT /integration-api/v1/orders/(id_or_external_ref)
Only the following status transitions are allowed:
approved
→paused
orcancelled
paused
→approved
orcancelled
cancelled
is a final status that cannot be changed
Path Parameters
Parameter | Type | Description | Required |
---|---|---|---|
id_or_external_ref | string | Internal ID or external reference | Yes |
Query Parameters
Parameter | Type | Description | Required |
---|---|---|---|
id_type | string | internal or external | Yes |
product_id | string | Specific product ID to update (optional) | No |
product_type | string | Required if product_id is used | Conditional |
Request Body
Field | Type | Description | Required |
---|---|---|---|
status | string | New status (approved , paused , cancelled ) | Conditional |
expiration_date | string | New expiration date (YYYY-MM-DD) or null to remove | Conditional |
At least one of status
or expiration_date
must be provided.
Example Request
{
"expiration_date": "2025-12-31",
"status": "paused"
}
Response
A successful update returns 200 OK
with the updated order details in the same format as the Create response.
Response Codes
Code | Description |
---|---|
200 | Order updated successfully |
422 | Validation error (details in response) |
404 | Order not found |
401 | Unauthorized (invalid API token) |
Cancel an Order
Cancel an order, revoking access to the associated products.
Endpoint: DELETE /integration-api/v1/orders/(id_or_external_ref)
Cancellation is irreversible. Once an order is cancelled, it cannot be reactivated.
Path Parameters
Parameter | Type | Description | Required |
---|---|---|---|
id_or_external_ref | string | Internal ID or external reference | Yes |
Query Parameters
Parameter | Type | Description | Required |
---|---|---|---|
id_type | string | internal or external | Yes |
Request Body (Optional)
Field | Type | Description | Required |
---|---|---|---|
reason | string | Reason for cancellation (max 150 chars) | No |
expiration_date | string | Future date for cancellation (YYYY-MM-DD) | No |
Response
A successful cancellation returns 200 OK
with:
Field | Type | Description |
---|---|---|
id | string | Publica.la's internal order ID |
external_reference | string | Your external reference ID |
Example Response
{
"data": {
"id": "03033649-de10-404b-aa8a-8682871001c2",
"external_reference": "123-abc"
}
}
Response Codes
Code | Description |
---|---|
200 | Order cancelled successfully |
422 | Validation error (details in response) |
404 | Order not found |
401 | Unauthorized (invalid API token) |
Common Error Scenarios
Error | Description | Solution |
---|---|---|
Invalid user ID | User ID doesn't exist or can't be created | Check user ID format and data |
Invalid product ID | Product ID doesn't exist or can't be created | Ensure product details are complete if auto-creation is needed |
Invalid status transition | Attempting disallowed status change | Only use allowed status transitions |
Order not found | The specified order doesn't exist | Verify ID and id_type parameter |
Expired checkout | Checkout URL has expired | Get a fresh checkout URL using the GET endpoint |
Related API Documentation
- Plans API: Create and manage subscription plans
- Users API: Manage user accounts
- Content API: Manage content products