API - अवलोकनAPI - कनेक्शन और प्राधिकरण API कुंजियाँ सेट करें, कनेक्शन जाँचें और त्रुटियों को संभालने व अनुरोध सीमाओं के बारे में जानें।
विषय सूची https://alterproduct.com/public-api/v1
ई-कॉमर्स सेटिंग पैनल में API क्रेडेंशियल बनाएँ। Access Token केवल एक बार दिखता है, इसलिए उसे तुरंत बैकएंड के सीक्रेट स्टोरेज में रखें।
Access Key और Access Token अपने सर्वर पर रखें। प्रमाणीकरण वाले एंडपॉइंट ब्राउज़र से आने वाली ऐसी कॉल अस्वीकार करते हैं जिनमें Origin या Referer हेडर हों।
क्रेडेंशियल के अनुमति-क्षेत्र सीमित किए जा सकते हैं। सक्रिय स्टोरफ़्रंट, योजना की क्षमताएँ और क्रेडेंशियल के अनुमति-क्षेत्र जाँचने के लिए GET /auth/check इस्तेमाल करें।
x-alter-access-key: YOUR_API_KEY
x-alter-access-token: YOUR_API_TOKENपैरामीटर आवश्यक विवरण x-alter-access-keyहाँ क्रेडेंशियल का सार्वजनिक पहचानकर्ता। x-alter-access-tokenहाँ ऐक्सेस कुंजी से जुड़ा गोपनीय टोकन। x-alter-client-fingerprintनहीं एम्बेड सेशन की दर सीमित करने के लिए वैकल्पिक स्थिर फ़िंगरप्रिंट। Authorizationकेवल रनटाइम POST /embed/session से लौटाया गया Bearer टोकन, जिसे /runtime/bootstrap इस्तेमाल करता है।
लाइव एकीकरण में सिंक या एम्बेड सुविधाएँ चालू करने से पहले प्रमाणीकरण जाँच एंडपॉइंट इस्तेमाल करें।
GET https://alterproduct.com/public-api/v1/auth/check उदाहरण अनुरोध (fetch)
const response = await fetch ( 'https://alterproduct.com/public-api/v1/auth/check' , {
method : 'GET' ,
headers : {
'x-alter-access-key' : process . env . ALTER_ACCESS_KEY ,
'x-alter-access-token' : process . env . ALTER_ACCESS_TOKEN
}
} ) ;
const payload = await response . json ( ) ;
if ( ! response . ok ) {
throw new Error ( payload ?. code || payload ?. error || ` Alter API ${ response . status } ` ) ;
}
console . log ( payload ) ; उदाहरण जवाब
{
"ok" : true ,
"message" : "success" ,
"storefrontId" : 12 ,
"userOwnerId" : 34 ,
"credentialId" : 56 ,
"scopes" : [ "orders:read" , "orders:write" , "products:read" ] ,
"plan" : {
"requiredPlan" : "Business" ,
"currentPlanName" : "Business" ,
"eligible" : true ,
"runtimeFlags" : {
"viewer" : true ,
"configurator" : true ,
"customizer" : true
} ,
"limits" : {
"activeRuntimeBindingsLimit" : 100 ,
"monthlyReassignmentLimit" : 1000 ,
"monthlyEmbedTokenLimit" : 50000
}
}
} नीचे दिया हेल्पर बाकी उदाहरणों में इस्तेमाल होता है। यह साधारण fetch है और Node.js 18+ या fetch देने वाले किसी सर्वर रनटाइम में चल सकता है।
const ALTER_API_BASE = 'https://alterproduct.com/public-api/v1' ;
const authHeaders = {
'x-alter-access-key' : process . env . ALTER_ACCESS_KEY ,
'x-alter-access-token' : process . env . ALTER_ACCESS_TOKEN
} ;
async function alterFetch ( path , options = { } ) {
const response = await fetch ( ` ${ ALTER_API_BASE } ${ path } ` , {
... options ,
headers : {
... authHeaders ,
... ( options . body ? { 'Content-Type' : 'application/json' } : { } ) ,
... options . headers
}
} ) ;
const payload = await response . json ( ) . catch ( ( ) => null ) ;
if ( ! response . ok ) {
throw new Error ( payload ?. code || payload ?. error || ` Alter API ${ response . status } ` ) ;
}
return payload ;
} अधिकांश कंट्रोलर त्रुटियाँ code वाले जवाब में एकरूप की जाती हैं। प्रमाणीकरण मिडलवेयर और रेट लिमिटर इसके बजाय error वाला जवाब दे सकते हैं।
// Controller error
{
"code" : "assetCatalog.invalidType"
}
// Auth middleware or rate limit
{
"error" : "Unauthorized"
}
{
"error" : "Too Many Requests"
} प्रकार सीमा समय अवधि वैश्विक600 अनुरोध 60 सेकंड GET /auth/check60 अनुरोध 60 सेकंड ऑर्डर पढ़ना/उत्पाद पढ़ना300 अनुरोध 60 सेकंड ऑर्डर लिखना/एम्बेड सेशन/रनटाइम बाइंडिंग120 अनुरोध 60 सेकंड एसेट/डिज़ाइन आयात पढ़ना180 अनुरोध 60 सेकंड फ़ॉन्ट300 अनुरोध 60 सेकंड WP कनेक्ट एक्सचेंज30 अनुरोध 60 सेकंड GET /model-generator/*600 अनुरोध 60 सेकंड
API - अवलोकनAPI - Viewer, Configurator और Customizer