اجلب المنتجات واربطها بالأدوات، وأنشئ جلسات آمنة لتضمين Viewer وConfigurator وCustomizer.
تستخدم الأمثلة الدالة المساعدة alterFetch وترويسات authHeaders على الخادم، كما هو موضح في دليل الاتصال. احتفظ بمفاتيح API على الخادم فقط.
الاتصال والتفويض والدالة المساعدة alterFetch تعيد نقاط نهاية المنتجات تصاميم واجهة المتجر التي يمكن تضمينها كتجارب viewer أو configurator أو customizer.
المعلمة مطلوب التفاصيل nameلاالبحث باسم المنتج/التصميم. customizerلاtrue أو false. offsetلاالقيمة الافتراضية 0. يجب أن تكون >= 0. limitلاالقيمة الافتراضية 9، والحد الأقصى 50. order_byلاid أو name أو created_at. directionلاASC أو DESC.
مثال طلب (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' ) ; مثال رد
{
"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
}
} تربط روابط بيئة التشغيل منتجات التجارة الخارجية بتصاميم Alter Product وأنواع بيئات التشغيل. تستخدمها أساسًا تكاملات WordPress/WooCommerce والخلفيات البرمجية المتقدمة لواجهات المتاجر.
المعلمة مطلوب التفاصيل designIdلامعرّف تصميم Alter Product التابع لواجهة المتجر. externalProductIdنعم للمزامنةمعرّف منتج خارجي، مثل معرّف منتج WooCommerce. runtimeTypeنعم للمزامنةviewer أو configurator أو customizer. statusلاdraft أو active أو inactive أو archived أو legacy_active. legacyStorefrontProductIdلامعرّف ربط قديم اختياري. legacyBindingMetaلابيانات وصفية JSON اختيارية، مثل manifestHash.
مثال طلب (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'
}
}
}
]
} )
} ) ; مثال رد
{
"message" : "runtimeBinding.syncCompleted" ,
"runtimeBindings" : [
{
"id" : 42 ,
"designId" : 381 ,
"externalProductId" : "wc_123" ,
"runtimeType" : "customizer" ,
"status" : "active"
}
]
} أنشئ رمز تضمين قصير الأجل من خادمك ومرّره إلى iframe/بيئة التشغيل، ثم دع بيئة التشغيل تستدعي bootstrap باستخدام رمز Bearer.
المعلمة مطلوب التفاصيل runtimeBindingIdموصى بهالمعرّف المفضل لروابط بيئة التشغيل النشطة. toolمطلوب عند غياب runtimeBindingIddesigner | viewer | configurator | customizer | model-generator toolIdtool: model-generatorالمعرّف الرقمي الموجب لمشروع المولّد المحلي، وليس UUID الخاص به أو معرّف منتج WooCommerce. originنعمأصل الموقع الذي يُعرض فيه التضمين، مثل https://yourstore.com. designIdمعرّف واحدمعرّف تصميم Alter Product. لا تجمعه مع orderId. orderIdمعرّف واحدمعرّف طلب Customizer. صالح فقط لـ customizer. cartKey + cartModeلاسياق سلة خاص بـ customizer فقط. تكون cartMode إما view أو edit.
مثال طلب (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 } ) ; ملاحظات
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
} )
} ) ; مثال رد
{
"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
}