Order event tickets
Creates an order for event tickets.
What this example does:
- Signs the user in
- Gets the tickets form and expands the schedule into time slots
- Creates an order for the selected ticket and a payment session for it
Prerequisites:
- A valid PROJECT_URL and APP_TOKEN for the OneEntry API.
- A registered user to sign in with
- A form with marker "tickets_form" and fields "schedule" and "tickets"
- Configured order storage with marker "tickets"
Notes:
- The examples handle errors minimally: they throw when a call returns an error object.
- By default (
isShell: true) the SDK returns an error object instead of throwing, so check the result, e.g.'statusCode' in result. WithisShell: falseit throws, and you handle errors with try/catch. See Errors.
Platform docs:
SDK reference:
Try it live
Run this example in the JS SDK sandbox. Connect your Project URL and App Token on first visit, then open:
Scenario
1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
2. Create an API client with defineOneEntry()
const { AuthProvider, Forms, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Authenticate the user with AuthProvider.auth()
const authData = [
{ marker: 'email_reg', value: 'your-email' },
{ marker: 'password_reg', value: 'your-password' },
];
const authResponse = await AuthProvider.auth('email', { authData });
if ('statusCode' in authResponse) {
throw new Error(authResponse.message);
}
console.log(authResponse);
Result:
{
"userIdentifier": "john@example.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ",
"refreshToken": "1745494429101-...-2834edf8"
}
4. Get the form from the OneEntry Platform with Forms.getFormByMarker() to build it on the frontend
const form = await Forms.getFormByMarker('tickets_form');
if ('statusCode' in form) {
throw new Error(form.message);
}
console.log(form);
Result:
{
"id": 9,
"attributeSetId": 12,
"type": "order",
"localizeInfos": {
"title": "Tickets",
"titleForSite": "Tickets",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 6,
"position": 1,
"identifier": "tickets_form",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "timeInterval",
"marker": "schedule",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Schedule",
"intervals": [
{
"id": "ef9cf848-7373-4b81-98bd-7ad33aa951e2",
"range": [
"2025-04-26T21:00:00.000Z",
"2025-04-26T21:00:00.000Z"
],
"external": [],
"intervals": [
{
"id": "f2042e47-c650-4fc6-ae1c-efdb109b450f",
"end": {
"hours": 21,
"minutes": 30
},
"start": {
"hours": 16,
"minutes": 30
},
"period": 90
}
],
"inEveryWeek": true,
"inEveryMonth": true
}
]
},
"additionalFields": {}
},
{
"type": "entity",
"marker": "tickets",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [
{
"title": "Tickets",
"value": {
"id": 8,
"depth": 0,
"isPinned": false,
"parentId": null,
"position": "0|hzzzz3:"
}
},
{
"title": "Bronze",
"value": {
"id": "p-8-10",
"depth": 1,
"isPinned": false,
"parentId": 8,
"position": 1,
"selected": true
}
},
{
"title": "Silver",
"value": {
"id": "p-8-11",
"depth": 1,
"isPinned": false,
"parentId": 8,
"position": 2,
"selected": true
}
},
{
"title": "Gold",
"value": {
"id": "p-8-12",
"depth": 1,
"isPinned": false,
"parentId": 8,
"position": 3,
"selected": true
}
}
],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Tickets"
},
"additionalFields": {}
}
],
"total": "1",
"moduleFormConfigs": []
}
The schedule attribute carries a compact recurrence rule, not a list of slots. Turn it into concrete [start, end] pairs for the dates you render with expandTimeIntervals; see Time intervals:
import { expandTimeIntervals } from 'oneentry';
const field = form.attributes.find((a) => a.marker === 'schedule');
const slots = (field?.localizeInfos.intervals ?? []).flatMap((schedule) =>
expandTimeIntervals(schedule, { from: '2025-04-01', to: '2025-04-30' }),
);
5. Create an order in the order storage with Orders.createOrder()
const body = {
formIdentifier: 'tickets_form',
paymentAccountIdentifier: 'cash',
formData: [{ type: 'entity', marker: 'tickets', value: ['p-8-10'] }],
products: [{ productId: 10, quantity: 1 }],
};
const order = await Orders.createOrder('tickets', body);
if ('statusCode' in order) {
throw new Error(order.message);
}
Result:
{
"id": 123,
"formIdentifier": "tickets_form",
"paymentAccountIdentifier": "cash",
"formData": [
{
"type": "entity",
"marker": "tickets",
"value": [
"p-8-10"
]
}
],
"products": [
{
"productId": 10,
"quantity": 1
}
],
"currency": "USD",
"totalSum": 100,
"bonusApplied": 0,
"totalDue": 100,
"discountConfig": {
"orderDiscounts": [],
"productDiscounts": [],
"coupon": null,
"settings": {
"allowStacking": false,
"maxDiscountValue": null,
"allowGiftStacking": false,
"maxBonusPaymentPercent": null,
"minBonusAmount": null,
"minOrderAmountForBonus": null,
"giftRefundPolicy": "KEEP_GIFT"
},
"additionalDiscountsMarkers": [],
"totalRaw": 100,
"totalSumWithDiscount": 100,
"excludedGiftProductIds": [],
"bonus": {
"availableBalance": 0,
"maxBonusDiscount": 0,
"minBonusAmount": null,
"minOrderAmountForBonus": null,
"bonusApplied": 0
},
"bonusApplied": 0,
"totalDue": 100
},
"statusIdentifier": "new",
"statusLocalizeInfos": {
"title": "new"
},
"createdDate": "2026-06-06T11:54:31.545Z"
}
6. Create a payment session with Payments.createSession()
const paymentSession = await Payments.createSession(order.id, 'session', false);
if ('statusCode' in paymentSession) {
throw new Error(paymentSession.message);
}
console.log(paymentSession);
Result:
{
"id": 71,
"createdDate": "2026-06-06T11:54:31.857Z",
"updatedDate": "2026-06-06T11:54:31.857Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 123,
"amount": null,
"paymentUrl": null
}
7. Get the payment session by order ID with Payments.getSessionByOrderId()
const sessionByOrderId = await Payments.getSessionByOrderId(order.id);
if ('statusCode' in sessionByOrderId) {
throw new Error(sessionByOrderId.message);
}
console.log(sessionByOrderId);
Result:
[
{
"id": 71,
"createdDate": "2026-06-06T11:54:31.857Z",
"updatedDate": "2026-06-06T11:54:31.857Z",
"type": "session",
"status": "waiting",
"paymentAccountId": 1,
"orderId": 123,
"amount": null,
"paymentUrl": null
}
]
Final example
// 1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
// 2. Create an API client
const { AuthProvider, Forms, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Sign in
const authData = [
{ marker: 'email_reg', value: 'your-email' },
{ marker: 'password_reg', value: 'your-password' },
];
const authResponse = await AuthProvider.auth('email', { authData });
if ('statusCode' in authResponse) {
throw new Error(authResponse.message);
}
console.log(authResponse);
// 4. Get the form to build it on the frontend
const form = await Forms.getFormByMarker('tickets_form');
if ('statusCode' in form) {
throw new Error(form.message);
}
console.log(form);
// 5. Create an order in the order storage
const body = {
formIdentifier: 'tickets_form',
paymentAccountIdentifier: 'cash',
formData: [{ type: 'entity', marker: 'tickets', value: ['p-8-10'] }],
products: [{ productId: 10, quantity: 1 }],
};
const order = await Orders.createOrder('tickets', body);
if ('statusCode' in order) {
throw new Error(order.message);
}
// 6. Create a payment session
const paymentSession = await Payments.createSession(order.id, 'session', false);
if ('statusCode' in paymentSession) {
throw new Error(paymentSession.message);
}
console.log(paymentSession);
// 7. Get the payment session by order ID
const sessionByOrderId = await Payments.getSessionByOrderId(order.id);
if ('statusCode' in sessionByOrderId) {
throw new Error(sessionByOrderId.message);
}
console.log(sessionByOrderId);