Obtenir tous les formulaires
Récupère tous les formulaires configurés dans le projet.
Ce que fait cet exemple :
- Obtient la liste de tous les formulaires du projet OneEntry.
- Examine les identifiants, les types et les schémas de champs des formulaires.
- Utilise les identifiants de formulaire avec getFormByMarker() pour récupérer le détail complet des champs.
Prérequis :
- Un PROJECT_URL et un APP_TOKEN valides pour l'API OneEntry.
- Au moins un formulaire configuré dans le panneau d'administration OneEntry.
Remarques :
- Renvoie un objet paginé,
{ items, total }. Passez l'identifiant d'un formulaire à Forms.getFormByMarker() pour l'obtenir avec le détail complet des champs. - Par défaut (
isShell: true), le SDK renvoie un objet d'erreur au lieu de lever une exception : vérifiez donc le résultat, par ex.'statusCode' in result. AvecisShell: false, il lève une exception, et vous gérez les erreurs avec try/catch. Voir Errors.
Documentation de la plateforme :
Référence du SDK :
Essayer en direct
Exécutez cet exemple dans le bac à sable JS SDK. Lors de la première visite, connectez l'URL de votre projet et votre App Token, puis ouvrez :
Scénario
1. Importer defineOneEntry et définir PROJECT_URL et APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
2. Créer un client API avec defineOneEntry()
const { Forms } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Obtenir tous les formulaires avec Forms.getAllForms()
const forms = await Forms.getAllForms('en_US');
if ('statusCode' in forms) {
throw new Error(forms.message);
}
Résultat :
{
"items": [
{
"id": 1,
"attributeSetId": 4,
"type": "data",
"localizeInfos": {
"title": "Schedule",
"titleForSite": "",
"successMessage": "Message about successful data processing",
"unsuccessMessage": "Message about unsuccessful data processing",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 9,
"position": 1,
"identifier": "schedule",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "timeInterval",
"marker": "schedule",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Schedule",
"intervals": [
{
"id": "d048af40-bd75-4f7f-ae8d-982d2f2746aa",
"range": [
"2025-04-20T21:00:00.000Z",
"2025-04-20T21:00:00.000Z"
],
"external": [],
"intervals": [
{
"id": "f27a6b86-31a8-4cf1-ad3a-86b184b4269f",
"end": {
"hours": 19,
"minutes": 0
},
"start": {
"hours": 9,
"minutes": 0
},
"period": 60
}
],
"inEveryWeek": true,
"inEveryMonth": true
},
{
"id": "dcde4900-5ba1-4394-b020-12cdabc514c6",
"range": [
"2025-04-21T21:00:00.000Z",
"2025-04-21T21:00:00.000Z"
],
"external": [],
"intervals": [
{
"id": "11168047-8428-415d-ac77-4a7757892fe4",
"end": {
"hours": 19,
"minutes": 0
},
"start": {
"hours": 16,
"minutes": 0
},
"period": 60
}
],
"inEveryWeek": true,
"inEveryMonth": true
}
]
},
"additionalFields": {}
}
]
},
{
"id": 2,
"attributeSetId": 1,
"type": "data",
"localizeInfos": {
"title": "Entity",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 17,
"position": 2,
"identifier": "entity",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "entity",
"marker": "entity",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [
{
"title": "Blue service",
"value": {
"id": "p-2-7",
"depth": 0,
"isPinned": false,
"parentId": null,
"position": 2,
"selected": true
}
},
{
"title": "Green service",
"value": {
"id": "p-2-6",
"depth": 0,
"isPinned": false,
"parentId": null,
"position": 3,
"selected": true
}
},
{
"title": "Red service",
"value": {
"id": "p-2-2",
"depth": 0,
"isPinned": false,
"parentId": null,
"position": 4,
"selected": true
}
}
],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Entity"
},
"additionalFields": {}
}
]
},
{
"id": 3,
"attributeSetId": 2,
"type": "data",
"localizeInfos": {
"title": "Contact us",
"titleForSite": "",
"successMessage": "Message about successful data processing",
"unsuccessMessage": "Message about unsuccessful data processing",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 5,
"position": 3,
"identifier": "contact_us",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "string",
"marker": "first_name",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "First name"
},
"additionalFields": {}
},
{
"type": "string",
"marker": "email",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
},
"emailInspectionValidator": true
},
"initialValue": null,
"localizeInfos": {
"title": "Email"
},
"additionalFields": {}
},
{
"type": "string",
"marker": "surname",
"position": 3,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"stringInspectionValidator": {
"stringMax": 0,
"stringMin": 0,
"stringLength": 0
}
},
"initialValue": null,
"localizeInfos": {
"title": "Surname"
},
"additionalFields": {}
},
{
"type": "list",
"marker": "topic",
"position": 4,
"settings": {},
"isVisible": true,
"listTitles": [
{
"title": "Article",
"value": "article",
"extended": {
"type": null,
"value": null
},
"position": 1
},
{
"title": "Article-2",
"value": "article-2",
"extended": {
"type": null,
"value": null
},
"position": 2
}
],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Topic"
},
"additionalFields": {}
},
{
"type": "text",
"marker": "text",
"position": 5,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Text"
},
"additionalFields": {}
},
{
"type": "button",
"marker": "send",
"position": 7,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Send"
},
"additionalFields": {}
}
]
},
{
"id": 4,
"attributeSetId": 5,
"type": "sign_in_up",
"localizeInfos": {
"title": "Registration",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 0,
"position": 4,
"identifier": "reg",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "string",
"marker": "email_reg",
"isLogin": true,
"isSignUp": false,
"position": 1,
"settings": {},
"isVisible": true,
"isPassword": false,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
},
"emailInspectionValidator": true
},
"initialValue": null,
"localizeInfos": {
"title": "E-mail"
},
"additionalFields": {},
"isSignUpRequired": false,
"isNotificationEmail": false,
"isNotificationPhoneSMS": false,
"isNotificationPhonePush": false
},
{
"type": "string",
"marker": "name_reg",
"isLogin": false,
"isSignUp": true,
"position": 2,
"settings": {},
"isVisible": true,
"isPassword": false,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Name"
},
"additionalFields": {},
"isSignUpRequired": false,
"isNotificationEmail": false,
"isNotificationPhoneSMS": false,
"isNotificationPhonePush": false
},
{
"type": "string",
"marker": "phone_reg",
"isLogin": false,
"isSignUp": true,
"position": 3,
"settings": {},
"isVisible": true,
"isPassword": false,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Phone"
},
"additionalFields": {},
"isSignUpRequired": false,
"isNotificationEmail": false,
"isNotificationPhoneSMS": false,
"isNotificationPhonePush": false
},
{
"type": "string",
"marker": "password_reg",
"isLogin": false,
"isSignUp": false,
"position": 4,
"settings": {},
"isVisible": true,
"isPassword": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
},
"stringInspectionValidator": {
"stringMax": 0,
"stringMin": 0,
"stringLength": 0
}
},
"initialValue": null,
"localizeInfos": {
"title": "Password"
},
"additionalFields": {},
"isSignUpRequired": false,
"isNotificationEmail": false,
"isNotificationPhoneSMS": false,
"isNotificationPhonePush": false
},
{
"type": "string",
"marker": "email_notification_reg",
"isLogin": false,
"isSignUp": false,
"position": 5,
"settings": {},
"isVisible": true,
"isPassword": false,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "email for notification"
},
"additionalFields": {},
"isSignUpRequired": false,
"isNotificationEmail": true,
"isNotificationPhoneSMS": false,
"isNotificationPhonePush": false
}
]
},
{
"id": 5,
"attributeSetId": 3,
"type": "order",
"localizeInfos": {
"title": "Order",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 2,
"position": 5,
"identifier": "order",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "string",
"marker": "name",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Name"
},
"additionalFields": {}
}
]
},
{
"id": 6,
"attributeSetId": 8,
"type": "order",
"localizeInfos": {
"title": "Subscription",
"titleForSite": "Subscription",
"successMessage": "Message about successful data processing",
"unsuccessMessage": "Message about unsuccessful data processing",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 21,
"position": 6,
"identifier": "subscription",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "date",
"marker": "expired_date",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Expired date"
},
"additionalFields": {}
},
{
"type": "list",
"marker": "subscription_time",
"position": 5,
"settings": {},
"isVisible": true,
"listTitles": [
{
"title": "1 month",
"value": "1",
"extended": {
"type": "real",
"value": "100"
},
"position": 1
},
{
"title": "6 months",
"value": "6",
"extended": {
"type": "real",
"value": "500"
},
"position": 2
},
{
"title": "1 year",
"value": "12",
"extended": {
"type": "real",
"value": "999"
},
"position": 3
}
],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Subscription time"
},
"additionalFields": {}
}
]
},
{
"id": 7,
"attributeSetId": 10,
"type": "order",
"localizeInfos": {
"title": "Guest order",
"titleForSite": "",
"successMessage": "Message about successful data processing",
"unsuccessMessage": "Message about unsuccessful data processing",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 0,
"position": 7,
"identifier": "guest_order",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "string",
"marker": "guest_phone",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Phone"
},
"additionalFields": {}
},
{
"type": "string",
"marker": "guest_name",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Name"
},
"additionalFields": {}
},
{
"type": "string",
"marker": "guest_email",
"position": 3,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Email"
},
"additionalFields": {}
}
]
},
{
"id": 8,
"attributeSetId": 11,
"type": "data",
"localizeInfos": {
"title": "File",
"titleForSite": "",
"successMessage": "Successful data processing",
"unsuccessMessage": "Unsuccessful data processing",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 0,
"position": 8,
"identifier": "file",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "file",
"marker": "file",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "File"
},
"additionalFields": {}
},
{
"type": "image",
"marker": "image",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Image"
},
"additionalFields": {}
},
{
"type": "groupOfImages",
"marker": "images_group",
"position": 3,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Images group"
},
"additionalFields": {}
}
]
},
{
"id": 9,
"attributeSetId": 12,
"type": "order",
"localizeInfos": {
"title": "Tickets",
"titleForSite": "Tickets",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 6,
"position": 9,
"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": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Tickets"
},
"additionalFields": {}
}
]
},
{
"id": 10,
"attributeSetId": 15,
"type": "data",
"localizeInfos": {
"title": "Spam form",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 0,
"position": 10,
"identifier": "spam_form",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "string",
"marker": "first_name",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "First name"
},
"additionalFields": {}
},
{
"type": "string",
"marker": "surname",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"stringInspectionValidator": {
"stringMax": 0,
"stringMin": 0,
"stringLength": 0
}
},
"initialValue": null,
"localizeInfos": {
"title": "Surname"
},
"additionalFields": {}
},
{
"type": "spam",
"marker": "spam",
"position": 3,
"settings": {
"captcha": {
"key": "6LenQZAsAAAAAF5EGcFYz_IbyV7l2_4NGgiCiP6e",
"domainNames": [
"localhost"
]
}
},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "You're not a robot?"
},
"additionalFields": {}
}
]
}
],
"total": 10
}
4. Accéder aux champs du formulaire
forms.items.forEach(form => {
const identifier = form.identifier; // "contact_us", "reg", "schedule", ...
const title = form.localizeInfos?.title;
const type = form.type; // "order" | "sign_in_up" | "collection" | "data" | "rating" | null
const fields = form.attributes; // array of form fields, sorted by position
console.log(identifier, title, type, fields);
});
form.attributesest toujours un tableau (vide lorsque le formulaire n'a pas de champs) trié parposition: vous pouvez donc l'afficher tel quel. Un champtimeIntervalporte une règle de récurrence danslocalizeInfos.intervals; développez-la avecexpandTimeIntervals.
Résultat (valeurs pour un formulaire) :
{
"identifier": "spam_form",
"title": "Spam form",
"type": "data",
"fields": [
{
"type": "string",
"marker": "first_name",
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "First name"
},
"additionalFields": {}
},
{
"type": "string",
"marker": "surname",
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"stringInspectionValidator": {
"stringMax": 0,
"stringMin": 0,
"stringLength": 0
}
},
"initialValue": null,
"localizeInfos": {
"title": "Surname"
},
"additionalFields": {}
},
{
"type": "spam",
"marker": "spam",
"position": 3,
"settings": {
"captcha": {
"key": "6LenQZAsAAAAAF5EGcFYz_IbyV7l2_4NGgiCiP6e",
"domainNames": [
"localhost"
]
}
},
"isVisible": true,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "You're not a robot?"
},
"additionalFields": {}
}
]
}
Exemple final
// 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 { Forms } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Get all forms with Forms.getAllForms()
const forms = await Forms.getAllForms('en_US');
if ('statusCode' in forms) {
throw new Error(forms.message);
}
// 4. Access form fields
forms.items.forEach(form => {
const identifier = form.identifier; // "contact_us", "reg", "schedule", ...
const title = form.localizeInfos?.title;
const type = form.type; // "order" | "sign_in_up" | "collection" | "data" | "rating" | null
const fields = form.attributes; // array of form fields
console.log(identifier, title, type, fields);
});