Saltar al contenido principal

Scripts

El recurso Script permite que una aplicación registre un archivo Javascript personalizado para cargarlo y ejecutarlo dentro de la tienda del comerciante.

El script se inserta automáticamente en el HTML de la tienda y su ejecución depende de la configuración definida en el script.

Las aplicaciones que necesiten utilizar scripts deben contar con el permiso scripts habilitado.
Este permiso informa al comerciante que la aplicación ejecutará código adicional dentro de su tienda.

aviso

Te recomendamos leer la siguiente guía antes de continuar: Crear scripts en tus apps

Importante

  • Es responsabilidad del desarrollador garantizar que el script no genere errores en la tienda.
  • Una vez desinstalada la aplicación, el script deja de cargarse automáticamente.
  • El script no debe depender de librerías existentes en el tema de la tienda.
  • Otras aplicaciones también pueden inyectar scripts al mismo tiempo.
  • El script se inyecta directamente en la tienda del comerciante.
<script
src="http://cdn.tiendanegocio.com/scripts/test/v2.js"
type="text/javascript"
></script>

Variable Global

Un objeto Javascript llamado TN está disponible dentro del contexto del script.

Este objeto contiene información general de la tienda, carrito, producto, orden y otras variables útiles según la página actual.

Página de la tienda

var TN = {

store: {
id: /* Store's id */,
url: /* Store's URL */
},

theme: {
code: /* Current theme's code */,
name: /* Current theme's name */
},

lang: /* Current language's code (e.g. es) */,

currency: {
cents_separator: /* Symbol used for separating cents */,
code: /* Current currency in ISO 4217 format */,
display_long: /* Currency format string when the currency is specified */,
display_short: /* Currency format string when the currency is not specified */,
thousands_separator: /* Symbol used for separating thousands */
},

country: /* Current country in ISO 3166-1 format */,

customer: /* Current customer id or null if there is no logged-in customer */

};

Página de producto

TN.product = {

id: /* Product's id */,

name: /* Product's name */,

categories: [ /* Product categories */ ],

requires_shipping: /* True if product requires physical shipping */

};

TN.variants = [ /* JSON with the variants */ ];

Página de categoría

TN.categories = [
{
id: /* Category's id */,
name: /* Category's name */,
slug: /* Category's slug */
}
];

Productos en el carrito

TN.cart = {

subtotal: /* Cart's subtotal */,

has_non_shippable_products: /* True if at least one product doesn't require physical shipping */,

has_shippable_products: /* True if at least one product requires physical shipping */,

items: [
{
id: /* Product Variant's id */,

name: /* Product Variant's name */,

promo_price: /* Product Variant's promo price or null */,

quantity: /* Quantity to be purchased */,

unit_price: /* Product Variant's price */
}
]

};

Página de pago

TN = {

cart: {

items: [
{
id: /* Product Variant's id */,

name: /* Product Variant's name */,

promo_price: /* Product Variant's promo price or null */,

quantity: /* Quantity to be purchased */,

unit_price: /* Product Variant's price in cents */
}
]

},

country: /* Current country in ISO 3166-1 format */,

currency: {

cents_separator: /* Symbol used for separating cents */,

code: /* Current currency in ISO 4217 format */,

display_long: /* Currency format string when the currency is specified */,

display_short: /* Currency format string when the currency is not specified */,

thousands_separator: /* Symbol used for separating thousands */

},

customer: /* Current customer id or null if there is no logged-in customer */,

lang: /* Current language's code (e.g. es) */,

store: {

id: /* Store's id */,

url: /* Store's URL */

}

};

Página de agradecimiento

TN.order = {

id: /* Order's id */,

number: /* Order's number */,

hash: /* Order's hash */,

total: /* Order's total */,

discount: /* Order's discount or null */,

coupon: /* Applied coupon or null */,

created_at: /* Order's creation date */

};

Endpoints públicos de Scripts

Get /scripts

ParámetroDescripción
idsLista de Id
qBusca por título o handle
pageNúmero de la página
per_pageCantidad a mostrar por página

Response
HTTP/1.1 200 OK

{
"result": [
{
"id": 7,
"commerce_script_id": 12,
"name": "mi script",
"handle": "mi-script",
"event": "onload",
"location": "store",
"created_at": "2026-05-15T13:31:10.000Z",
"updated_at": null,
"is_auto_install": true,
"params": {
"color": "red",
"enabled": "false"
},
"status": "active",
"current_version": null,
"draft_version": {
"id": 10,
"version": "v1",
"src": "http://..cdn/mi-script/v1.js"
}
}
],
"pagination": {
"total": 1,
"page": 1,
"per_page": 10,
"next_page": null
}
}

Get /scripts/{id}

Response
HTTP/1.1 200 OK

{
"id": 7,
"commerce_script_id": 12,
"name": "mi script",
"handle": "mi-script",
"event": "onload",
"location": "store",
"created_at": "2026-05-15T13:31:10.000Z",
"updated_at": null,
"is_auto_install": true,
"params": {
"color": "red",
"enabled": "false"
},
"status": "active",
"current_version": null,
"draft_version": {
"id": 10,
"version": "v1",
"src": "http://..cdn/mi-script/v1.js"
}
}

PUT /scripts/{id}

ParámetroDescripción
idId del script
paramsParámetros del script

Ejemplo de request

{
"params": {
"color": "blue",
"enabled": "true"
}
}

Respuesta
HTTP/1.1 200

{
"id": 7,
"commerce_script_id": 12,
"name": "mi scipt",
"handle": "mi-script",
"event": "onload",
"location": "store",
"created_at": "2026-05-15T13:31:10.000Z",
"updated_at": null,
"is_auto_install": true,
"params": {
"color": "blue",
"enabled": "true"
},
"status": "active",
"current_version": null,
"draft_version": {
"id": 10,
"version": "v1",
"src": "http://..cdn/mi-script/v1.js"
}
}

DELETE /scripts/{id}

  • Elimina el script de la tienda de manera lógica. Hace que deje de cargarse el script en esa tienda.

Respuesta
HTTP/1.1 200 OK

{
"message": "Script deleted successfully"
}