البدء السريع

اتصل بـ Listings API، واعرض مواقعك، وأنشئ موقعًا، ورُدّ على تقييم باستخدام TypeScript.

1. اضبط مفتاح API

احصل على مفتاحك من مفاتيح API → مفتاح جديد في لوحة التحكم للمطورين في Listings API.

bash
export LISTINGSAPI_KEY="your-api-key"

يقرأ new ListingsAPI() القيمة LISTINGSAPI_KEY من البيئة تلقائيًا، أو يمكنك تمرير apiKey صراحةً.

2. اعرض قائمة مواقعك

quickstart.ts
import { ListingsAPI } from 'listingsapi-js'; const client = new ListingsAPI(); const result = await client.fetchAllLocations({ first: 5 });if (!Array.isArray(result)) {for (const location of result.locations) {  console.log(location.name, '--', location.city, location.stateIso);}console.log('\nhasNextPage:', result.pageInfo.hasNextPage);}
bash
npx tsx quickstart.ts

المخرجات المتوقعة:

bash
Acme Dental Midtown -- New York NYAcme Dental Brooklyn -- Brooklyn NYAcme Dental Jersey City -- Jersey City NJ hasNextPage: false

يعيد fetchAllLocations كائنًا يحتوي على locations وpageInfo افتراضيًا. مرّر fetchAll: true ليتنقل SDK تلقائيًا بين الصفحات باستخدام المؤشر، ويعيد Location[] مسطّحًا بدلًا من ذلك.

TypeScript
const all = await client.fetchAllLocations({ fetchAll: true, pageSize: 100 });if (Array.isArray(all)) {console.log('Total: ' + all.length + ' locations');}

3. أنشئ موقعًا

تتطلب API الحقول name وcity وcountryIso وsubCategoryId، وقيمة للحقل description لا تقل عن 200 حرف. احصل على قيم صالحة للحقل subCategoryId من client.fetchSubcategories() واستخدم قيمة databaseId لكل عنصر.

TypeScript
const created = await client.createLocation({name: 'Acme Dental',storeId: 'ACME-NYC-001',street: '123 Jump Street',city: 'New York',stateIso: 'NY',postalCode: '10013',countryIso: 'US',phone: '6443859313',subCategoryId: 1432,description:  'Acme Dental is a family-owned dental practice serving downtown New York since 2009. ' +  'Our team provides preventive checkups, cosmetic dentistry, orthodontics, and emergency care, ' +  'with same-day appointments, transparent pricing, and a patient-first approach on every visit.',});console.log(created);

إذا كانت حمولة البيانات غير صالحة، يطرح SDK استثناءً من النوع ValidationError يتضمن عناصر الأخطاء الواردة من المنصة، حتى عندما تعيد API حالة HTTP 200. لا توجد علامة success للتحقق منها.

4. ردّ على تقييم

اجلب تقييمات موقع، ثم ردّ باستخدام معرّف التفاعل. تُقبل معرّفات المواقع الرقمية في جميع المواضع: يرمّزها SDK باستخدام base64 تلقائيًا.

TypeScript
const reviews = await client.fetchInteractions(16808, {startDate: '2026-01-01',endDate:   '2026-06-30',first: 10,}); if (!Array.isArray(reviews)) {const unanswered = reviews.interactions.find(  (review) => (review.responses ?? []).length === 0,);if (unanswered) {  console.log(unanswered.rating, unanswered.content?.slice(0, 80));  await client.respondToReview(    unanswered.id,    'Thank you for the kind words! We look forward to seeing you at your next visit.',  );}}

5. عالج الأخطاء

TypeScript
import { ListingsAPI, APIError, AuthenticationError } from 'listingsapi-js'; const client = new ListingsAPI({ apiKey: 'bad-key' }); try {await client.fetchAllLocations();} catch (error) {if (error instanceof AuthenticationError) {  console.log('Invalid API key. Check LISTINGSAPI_KEY.');} else if (error instanceof APIError) {  console.log('Status:', error.statusCode);  // can be 200 for payload-level errors  console.log('Code:',   error.code);        // first platform code, e.g. 'SY10005'  console.log('Errors:', error.errors);      // [{ code, message, context }, ...]}}

يطرح SDK أخطاء ذات أنواع محددة للاستجابات التي تكون رموز حالتها خارج نطاق 2xx، ولحمولات الأخطاء التي تعيدها المنصة مع حالة HTTP 200، ولعمليات الكتابة التي تُبلغ عن success: false. كما يعيد المحاولة تلقائيًا عند تلقي استجابات 429 و5xx. راجع معالجة الأخطاء للاطلاع على أنماط إعادة المحاولة وإرشادات رموز الحالة.

الخطوات التالية