Spaces:
Paused
Paused
File size: 2,892 Bytes
480e618 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
const axios = require('axios');
/**
* Test function to get event details using the REST API
* @param slug string - event slug (e.g. al-awwal-tour-stadium-tickets-843728)
* @param lang string - language code (default: 'en')
* @param visibleIn string - visibility filter (default: 'rs')
*/
async function getEventDetailsBySlug(slug, lang = 'en', visibleIn = 'rs') {
try {
const url = `https://api.webook.com/api/v2/event-detail/${slug}?lang=${lang}&visible_in=${visibleIn}`;
console.log(`Fetching event details from: ${url}`);
const response = await axios.get(url, {
headers: {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9,ar;q=0.8",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
}
});
if (response.data && response.data.status === 'success' && response.data.data) {
console.log('β
Success! Event details:');
console.log(JSON.stringify(response.data.data, null, 2));
return response.data.data;
} else {
console.log('β No data found or invalid response');
console.log('Response:', response.data);
return null;
}
} catch (error) {
console.error('β Error fetching event details:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
return null;
}
}
/**
* Extract slug from WeBook event URL and fetch details
* @param eventUrl string - full event URL
*/
async function getEventDetailsByUrl(eventUrl) {
try {
// Extract slug from URL
const match = eventUrl.match(/\/events\/([a-zA-Z0-9\-]+)/);
if (!match || !match[1]) {
console.log('β Could not extract slug from URL:', eventUrl);
return null;
}
const slug = match[1];
console.log(`Extracted slug: ${slug}`);
return await getEventDetailsBySlug(slug);
} catch (error) {
console.error('β Error extracting slug from URL:', error);
return null;
}
}
// Test the function with the provided example
async function test() {
console.log('π§ͺ Testing WeBook REST API...\n');
// Test 1: Direct slug
console.log('π Test 1: Direct slug');
await getEventDetailsBySlug('al-awwal-tour-stadium-tickets-843728');
console.log('\n' + '='.repeat(50) + '\n');
// Test 2: From URL
console.log('π Test 2: From URL');
await getEventDetailsByUrl('https://webook.com/en/events/al-awwal-tour-stadium-tickets-843728');
console.log('\n' + '='.repeat(50) + '\n');
// Test 3: Different language
console.log('π Test 3: Arabic language');
await getEventDetailsBySlug('al-awwal-tour-stadium-tickets-843728', 'ar', 'rs');
}
// Run the test
test().catch(console.error); |