Skip to main content

Orders

Order objects are created to handle end customers' purchases of already existing products. You can create, retrieve and update individual orders, as well as list all orders. Orders are identified by a unique autogenerated ID as well as an external ID set by yourself.

Base URL

All following endpoints operates over the URL of your store: https://your-store.com/

example: https://alephdigital.publica.la/

Endpoints

Headers

{
"Content-Type": "application/json",
"Accept": "application/json",
"X-User-Token": api_token,
}
info

Make sure you generated the api_token on your store. More info HERE

Create

POST /integration-api/v1/orders

example: https://your-store.com/integration-api/v1/orders

First of all, there are two types of orders.

  • Permission orders: Used to assign a publication or plan to a user. This would grant access, but it won't count as a transaction in the sales report
  • Sale orders: Used to generate a checkout session in a gateway. The order will remain in the 'pending' status until the user completes its payment in the gateway. If the payment is a success, the order then transitions to the 'approved' status. This order also grants access to a publication or plan, but it will be reported as a transaction in the sales report

Automatic creation of missing resources:

When creating both sale and permission orders, if the user doesn't exist, it's created automatically. That's why the user.id is required.

When creating sale orders only, if the product doesn't exist, it's created automatically. For this to happen, we need the product fields name and url, in addition to the fields already "required for sale".
The newly created product will be type "External link" and it will be pointing to that url. It will only be accessible through the API or the store dashboard, it won't be displayed in the storefront.

Completing the checkout for sale orders

When creating a sale order, the response will include a checkout.token property containing an external-auth-token url and checkout.ttl with its ttl in seconds. You should redirect your user to that URL, and we'll automatically authenticate them and redirect them to the corresponding gateway checkout. After they complete the payment, they will be redirected to the return_url you set for your order.
We will add a query string to that return_url containing the following payment data:

  • order-id: The order ID in our system
  • order-external-id: The order ID in your system
  • status: the resulting status after the payment (approved, pending, cancelled)

Keep in mind that a checkout.token expires after checkout.ttl seconds, you can always generate a new one manually or by retrieving the order using the GET endpoint

Body Request

FieldDescriptionRequired for permissionRequired for saleTypeFormat
typeOrder typeyesyesstringpermission or sale
external_referenceOrder unique ID in your systemnonostringmax 64
return_urlAn url to return to, after finishing the checkoutnoyesstringurl
unit_priceOrder pricenoyesfloat
currency_idOrder currencynoyesstringISO 4217. All supported for permission. Only ARS supported for sale
userUser objectyesyesobject
user.idUser unique ID in your systemRequired if user.email is nullyesstringmax 64
user.emailUser EmailRequired if user.id is nullnostringemail
productsList of productsyesyesobjects array
products.*.typeProduct typeyesyesstringcontent or subscription
products.*.idProduct unique ID in your systemyesyesstringmax 64
products.*.nameProduct namenoyes*stringmax 64. (*) It's required only when using the automatic creation of products
products.*.urlProduct urlnoyes*stringurl. (*) It's required only when using the automatic creation of products
products.*.unit_priceProduct pricenoyesfloatISO 4217. All supported for permission. Only ARS supported for sale
products.*.currency_idProduct currencynoyesstring
products.*.expiration_dateUser will lose access to the content at this datenonostringyyyy-mm-dd

JSON example for permission order:

{
"external_reference": "123-abc",
"user":{
"id": "123",
"email": "[email protected]"
},
"products": [{
"id": "123",
"type": "content",
"expiration_date": "2023-12-31"
}]
}

JSON example for sale order:

{
"external_reference": "123-abc",
"type": "sale",
"unit_price": 10,
"currency_id": "ARS",
"user":{
"id": "123",
"email": "[email protected]"
},
"products": [{
"id": "123",
"type": "content",
"unit_price": 10,
"currency_id": "ARS"
}]
}

Response

FieldDescriptionTypeFormat
idpublica.la's order unique IDstring
external_referenceOrder unique ID in your systemstring
sourceOrder creation sourcestringinternal or api
unit_priceOrder pricefloat
currency_idOrder currencystringISO 4217
statusstring
created_atDate when the order was created.stringyyyy-mm-dd
userobject
user.idUser unique ID in your systemstringmax 64
user.emailUser emailstringemail
productsList of productsobjects array
products.*.idProduct unique ID in your systemstring
products.*.typestringcontent or subscription
products.*.namestring
products.*.statusstring
products.*.expiration_dateUser will lose access to the content at this datestringyyyy-mm-dd
products.*.coverstring
products.*.reader_urlstring
products.*.unit_pricefloat

JSON example for permission:

{  
"data":
{
"id" : "03033649-de10-404b-aa8a-8682871001c2",
"external_reference": "123-abc",
"source": "api",
"unit_price": 12.9,
"currency_id": "USD",
"status": "approved",
"created_at": "2021-08-01",
"user":{
"id": "123",
"email": "[email protected]"
},
"products": [{
"id": "abc-123",
"type": "content",
"name": "abc product",
"status": "approved",
"expiration_date": "2021-12-31",
"cover": "https://cdn.publica.la/item/3213123.jpg",
"reader_url": "https://domain.com/reader/abc-product",
"description": "abc product is...",
"pages_quantity": 12,
"file_type": "pdf",
"is_free": false,
"unit_price": 10
}]
}
}

JSON example for sale (when just created and still pending):

{  
"data":
{
"id" : "03033649-de10-404b-aa8a-8682871001c2",
"external_reference": "123-abc",
"checkout": {
"url": "https://your-store.com/auth/token?external-auth-token={AURH-TOKEN}",
"expires_on" : "2023-01-01 12:00:00"
},
"source": "api",
"unit_price": 10,
"currency_id": "ARS",
"status": "pending",
"created_at": "2021-08-01",
"user":{
"id": "123",
"email": "[email protected]"
},
"products": [{
"id": "abc-123",
"type": "content",
"name": "abc product",
"status": "pending",
"cover": "https://cdn.publica.la/item/3213123.jpg",
"reader_url": "https://domain.com/reader/abc-product",
"description": "abc product is...",
"pages_quantity": 12,
"file_type": "pdf",
"is_free": false
}]
}
}
CodeDescription
200Ok
201Object Created
422Validation error, the reason of the error will be described in the response body
401Unauthenticated

JSON with errors example:

{
"status": 422,
"errors": [{
"title": "Incorrect User ID",
"details": ["Creation of the order failed due to incorrect user id"]
}]
}

Get

Using this endpoint you can either paginate through all the orders, search for orders by different parameters, or get a specific order by ID

GET /integration-api/v1/orders/{id || external_reference}?id_type= &user_email= &product_id &product_type= &start_at= &end_at=

tip

Using query parameter you can filter by id_type, user_email, product_id, product_type, or by date range using start_at, end_at.

examples:

  • Getting a specific order by the ID in our system:
    https://your-store.com/integration-api/v1/orders/some-id?id_type=internal
  • Getting a specific order by the ID in your system:
    https://your-store.com/integration-api/v1/orders/some-other-id?id_type=external
  • Searching for orders by product_id
    https://your-store.com/integration-api/v1/orders?product_id=some-product-id&product_type=content
  • Searching for orders by date range
    https://your-store.com/integration-api/v1/orders?start_at=2022-01-01&end_at=2022-06-01
  • Searching for orders by user email
    https://your-store.com/integration-api/v1/[email protected]
  • Getting all your orders
    https://your-store.com/integration-api/v1/orders

Parameters

FieldDescriptionTypeRequiredFormat
idMain or internal Order IDstringnomax 64
external_referenceExternal reference or order IDstringonly if id_type=externalmax 64

Query Params

FieldDescriptionTypeRequiredFormat
id_typeID typestringonly when we set an ID or external_reference parameterinternal or external
user_idUser unique ID in your systemstringIt is prioritized over user_emailmax 64
user_emailUser Emailstringemail
product_typestringonly when we set a product_idcontent or subscription
product_idProduct ID in your systemstringmax 64
start_atDate when the order was createdstringyyyy-mm-dd
end_atDate when the order was createdstringyyyy-mm-dd

Response

FieldDescriptionTypeFormat
idpublica.la's order unique IDstring
external_referenceOrder unique ID in your systemstring
checkout.tokenWhen the order is pending, the url to continue the checkoutstring
checkout.ttlWhen the order is pending, the ttl in secondsinteger
sourceOrder creation sourcestringinternal or api
unit_priceOrder pricefloat
currency_idOrder currencystringISO 4217
created_atDate when the order was created.stringyyyy-mm-dd
statusStatus of the orderstring'approved', 'cancelled', 'pending'
userContains details of the user.object
user.idUser unique ID in your systemstring
user.emailUser Emailstring
productsContains details of the product.array objectContains details of the products.
products.idProduct unique ID in your systemstring
products.typestringcontent or subscription
products.namestring
products.statusstring
products.expiration_dateUser will lose access to the content at this datestringyyyy-mm-dd
products.coverstring
products.reader_urlstring
products.unit_pricefloat

JSON example:

{"data": [{
"id": "c9f2b7b0-dc74-4c58-92a7-9dfcf93aed38",
"external_reference": "123-abc",
"unit_price": 17,
"currency_id": "USD",
"source": "api",
"user": {
"id": "123",
"email": "[email protected]"
},
"status": "approved",
"created_at": "2022-01-18",
"products": [
{
"id": "978-987-805-082-9",
"type": "content",
"name": "Lorem Ipsum",
"cover": "https://storage/thumbnail.jpg",
"expiration_date": "2023-12-31",
"reader_url": "https://domain.com/reader/lorem-ipsum",
"description": "",
"pages_quantity": 324,
"file_type": "PDF",
"is_free": false,
"unit_price": 17,
"status": "approved"
}
]
}]
}

Update

PUT /integration-api/v1/orders/{id || external_reference}?id_type=

example: https://your-store.com/integration-api/v1/orders/123-abc?id_type=external

This endpoint can only update the expiration date of an order or a product and status

info

The paused status is applied instantly. You won't have the permissions granted by the order in question until you change its status to approved.

Parameters

FieldDescriptionTypeRequiredFormat
idMain or internal Order IDstringyes, when we don’t have an external_referencemax 64
external_referenceExternal reference or order IDstringyes, when we don't have an idmax 64

Query params

FieldRequiredTypeFormat
id_typeyes, when using external_reference it should be externalstringinternal or external
product_idnostringmax 64
product_typeConditional. Required if product_id is not null.content or subscription

Body request

FieldRequiredTypeFormat
expiration_dateConditional. Required if status is null.stringyyyy-mm-dd
statusConditional. Required if expiration_date is null.stringapproved or paused
{
"expiration_date": "2023-12-31",
}

Response

FieldDescriptionTypeFormat
idpublica.la's order unique IDstring
external_referenceOrder unique ID in your systemstringstring
sourceOrder creation sourcestringinternal or api
unit_priceOrder pricefloat
currency_idOrder currencystringISO 4217
created_atDate when the order was created.stringyyyy-mm-dd
statusStatus of the orderstring'approved', 'paused', 'pending'
userContains details of the user.object
user.idUser unique ID in your systemstring
user.emailUser Emailstring
productsContains details of the product.array objectContains details of the products.
products.idProduct unique ID in your systemstring
products.typestringcontent or subscription
products.namestring
products.statusstring
products.expiration_dateUser will lose access to the content at this datestringyyyy-mm-dd
products.coverstring
products.reader_urlstring
products.unit_pricefloat

JSON example:

{  
"data": {
"id": "03033649-de10-404b-aa8a-8682871001c2",
"external_reference": "123-abc",
"unit_price": 12.9,
"currency_id": "USD",
"user":{
"id": "123",
"email": "[email protected]"
},
"status": "approved",
"created_at": "2020-04-13",
"products": [
{
"id": "abc-123",
"type": "content",
"name": "abc product",
"expiration_date": "2023-12-13",
"cover": "https://cdn.publica.la/item/3213123.jpg",
"reader_url": "https://domain.com/reader/abc-product",
"description": "abc product is...",
"pages_quantity": 12,
"file_type": "PDF",
"is_free": false,
"unit_price": 10,
"status": "approved"
}
]
}
}

CodeDescription
200Ok
201Object Created
422Validation error, the reason of the error will be described in the response body
401Unauthenticated

JSON with errors example:

{
"status": 422,
"errors": [{
"title": "Incorrect expiration date format",
"details": ["Update failed due to incorrect expiration date format"],
}]
}

Cancel

DELETE /integration-api/v1/orders/{id || external_reference}?id_type=

example: https://your-store.com/integration-api/v1/orders/123-abc?id_type=external

warning

Once deleted, the cancelled status cannot be reversed.

Parameters

FieldDescriptionTypeRequiredFormat
idMain or internal Order IDstringyes, when we don’t have an external_referencemax 64
external_referenceExternal reference or order IDstringyes, when we don't have an idmax 64

Query params

FieldRequiredTypeFormat
id_typeyes, when using external_reference it should be externalstringinternal or external

Body request

FieldDescriptionRequiredTypeFormat
reasonSet a reason why you cancel or revoke the access to the user.nostringmax 150
expiration_dateUser will lose access to the content at this date. If it is not specified and it is a subscription, it will be canceled once the current period has ended, otherwise the cancellation will be immediate.nostringyyyy-mm-dd

Response

FieldDescriptionType
idMain or internal order IDstring
external_referenceExternal reference or order IDstring

JSON example:

{  
"data": [
{
"id": "03033649-de10-404b-aa8a-8682871001c2",
"external_reference": "123-abc",
}
]
}
CodeDescription
200Ok
422Validation error, the reason of the error will be described in the response body
401Unauthenticated