Hämta produkter, koppla dem till verktygen och skapa säkra inbäddningssessioner för Viewer, Configurator och Customizer.
Exemplen använder hjälpfunktionen alterFetch på servern och authHeaders-headerfälten från anslutningsguiden. Förvara API-nycklar enbart på servern.
Anslutning, auktorisering och hjälpfunktionen alterFetch Produktändpunkterna returnerar butiksdesigner som kan bäddas in som Viewer-, Configurator- eller Customizer-upplevelser.
Parameter Obligatoriskt Detaljer namenejSöker efter produkt-/designnamn. customizernejtrue eller false. offsetnejStandard 0. Måste vara >= 0. limitnejStandard 9, högst 50. order_bynejid, name eller created_at. directionnejASC eller DESC.
Exempel på begäran (fetch)
const params = new URLSearchParams ( {
limit : '20' ,
offset : '0' ,
name : 't-shirt' ,
customizer : 'true' ,
order_by : 'created_at' ,
direction : 'DESC'
} ) ;
const products = await alterFetch ( ` /products? ${ params . toString ( ) } ` ) ;
const product = await alterFetch ( '/products/381' ) ; Exempel på svar
{
"products" : {
"items" : [
{
"id" : 381 ,
"name" : "Men's T-Shirt" ,
"createdAt" : "2026-01-03T23:55:05.000Z" ,
"productId" : 4 ,
"media" : {
"img" : {
"big" : "https://alterproduct.com/public-api/v1/file/public/products/4/big.png" ,
"medium" : "https://alterproduct.com/public-api/v1/file/public/products/4/medium.png" ,
"small" : "https://alterproduct.com/public-api/v1/file/public/products/4/small.png"
} ,
"mockups" : [ ]
} ,
"storefrontProduct" : {
"id" : 89 ,
"idUserDesign" : 381 ,
"shareAccess" : "public" ,
"isCustomizer" : 1
} ,
"runtimeBindings" : [
{
"id" : 42 ,
"runtimeType" : "customizer" ,
"status" : "active" ,
"externalProductId" : "wc_123"
}
] ,
"embeddable" : {
"viewer" : true ,
"configurator" : true ,
"customizer" : true
}
}
] ,
"total" : 1
}
} Runtimekopplingar kopplar externa e-handelsprodukter till Alter Product-designer och runtimetyper. De används främst av WordPress/WooCommerce-integrationer och avancerade butiksbackender.
Parameter Obligatoriskt Detaljer designIdnejAlter Product-design-ID som ägs av butiken. externalProductIdja för synkroniseringExternt produkt-ID, till exempel ett WooCommerce-produkt-ID. runtimeTypeja för synkroniseringviewer, configurator eller customizer. statusnejdraft, active, inactive, archived eller legacy_active. legacyStorefrontProductIdnejValfritt äldre kopplings-ID. legacyBindingMetanejValfria JSON-metadata, till exempel manifestHash.
Exempel på begäran (fetch)
await alterFetch ( '/runtime-bindings/sync-from-wordpress' , {
method : 'POST' ,
body : JSON . stringify ( {
bindings : [
{
externalProductId : 'wc_123' ,
runtimeType : 'customizer' ,
status : 'active' ,
designId : 381 ,
legacyBindingMeta : {
manifestHash : 'a3b1...'
}
}
]
} )
} ) ;
await alterFetch ( '/runtime-bindings/42' , {
method : 'PATCH' ,
body : JSON . stringify ( {
status : 'inactive'
} )
} ) ;
await alterFetch ( '/runtime-bindings/42/activate' , { method : 'POST' } ) ;
await alterFetch ( '/runtime-bindings/42/deactivate' , { method : 'POST' } ) ; wordpress_local
await alterFetch ( '/runtime-bindings/sync-from-wordpress' , {
method : 'POST' ,
body : JSON . stringify ( {
bindings : [
{
externalProductId : 'wc_123' ,
runtimeType : 'viewer' ,
status : 'active' ,
externalDesign : {
externalDesignKey : 'wp-design-381' ,
productId : 4 ,
title : 'WooCommerce local design' ,
manifestUrl : 'https://yourstore.com/wp-content/uploads/alter/381/manifest.json' ,
assetBaseUrl : 'https://yourstore.com/wp-content/uploads/alter/381/' ,
manifestHash : 'a3b1...' ,
sourceMeta : {
pluginVersion : '1.2.0'
}
}
}
]
} )
} ) ; Exempel på svar
{
"message" : "runtimeBinding.syncCompleted" ,
"runtimeBindings" : [
{
"id" : 42 ,
"designId" : 381 ,
"externalProductId" : "wc_123" ,
"runtimeType" : "customizer" ,
"status" : "active"
}
]
} Skapa en kortlivad inbäddningstoken på servern, skicka den till iframen/runtimemiljön och låt sedan runtimemiljön anropa bootstrap med en Bearer-token.
Parameter Obligatoriskt Detaljer runtimeBindingIdrekommenderasFöredragen identifierare för aktiva runtimekopplingar. toolkrävs utan runtimeBindingIddesigner | viewer | configurator | customizer | model-generator toolIdtool: model-generatorPositivt numeriskt ID för det lokala generatorprojektet, inte dess UUID eller WooCommerce-produktens ID. originjaOrigin där inbäddningen visas, till exempel https://yourstore.com. designIden identifierareAlter Product-design-ID. Kombinera inte med orderId. orderIden identifierareCustomizer-order-ID. Endast giltigt för customizer. cartKey + cartModenejKundvagnskontext endast för Customizer. cartMode är view eller edit.
Exempel på begäran (fetch)
const session = await alterFetch ( '/embed/session' , {
method : 'POST' ,
headers : {
'x-alter-client-fingerprint' : '9f1b7a5e4b3c2d1f9f1b7a5e4b3c2d1f'
} ,
body : JSON . stringify ( {
runtimeBindingId : 42 ,
origin : 'https://yourstore.com'
} )
} ) ;
const bootstrapResponse = await fetch ( 'https://alterproduct.com/public-api/v1/runtime/bootstrap' , {
method : 'GET' ,
headers : {
Authorization : ` Bearer ${ session . token } `
}
} ) ;
const bootstrap = await bootstrapResponse . json ( ) ;
console . log ( { session , bootstrap } ) ; Anmärkningar
await alterFetch ( '/embed/session' , {
method : 'POST' ,
body : JSON . stringify ( {
tool : 'customizer' ,
origin : 'https://yourstore.com' ,
orderId : 123
} )
} ) ;
await alterFetch ( '/embed/session' , {
method : 'POST' ,
body : JSON . stringify ( {
tool : 'viewer' ,
origin : 'https://yourstore.com' ,
designId : 381
} )
} ) ; Exempel på svar
{
"token" : "eyJhbGciOiJIUzI1NiIsImtpZCI6IjEifQ..." ,
"expiresIn" : 900 ,
"kid" : "1" ,
"mode" : "design" ,
"runtimeBindingId" : 42 ,
"runtimeType" : "customizer"
} Runtime bootstrap
{
"runtimeBindingId" : 42 ,
"designId" : 381 ,
"productId" : "wc_123" ,
"runtimeType" : "customizer" ,
"storageMode" : "wordpress_local" ,
"manifestUrl" : "https://yourstore.com/wp-content/uploads/alter/381/manifest.json" ,
"assetBaseUrl" : "https://yourstore.com/wp-content/uploads/alter/381/" ,
"manifestHash" : "a3b1..." ,
"planCapabilities" : {
"viewer" : true ,
"configurator" : true ,
"customizer" : true
} ,
"cartKey" : null ,
"cartMode" : null ,
"orderId" : null
}