GET
# Extract Location ID API

Parse TripAdvisor hotel URLs to extract the location ID needed for API calls.

## Overview

#### URL Parser Utility

Extract location IDs from any TripAdvisor hotel URL format. Essential for using location-based endpoints.

The Extract Location ID endpoint is a utility function that parses TripAdvisor URLs and extracts the location ID. This ID is required for many other TripAdvisor API endpoints.

### Endpoint URL

GET https://api.stayapi.com/v1/tripadvisor/location/extract-id 

## Query Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| url | string | Required | Any valid TripAdvisor hotel URL |

## Understanding Location IDs

### URL Structure

TripAdvisor URLs contain location IDs in this format:

 https://www.tripadvisor.com/Hotel\_Review-g1224250-d305165-Reviews-Hotel\_Name.html 

- g1224250 - Geographic location ID (city/region)
- d305165 - Property location ID (specific hotel)
- This API extracts the property ID (the number after "d")

## Supported URL Formats

### Standard URLs
`
              https://www.tripadvisor.com/Hotel_Review-g1224250-d305165-Reviews-The_Siam.html
            `

### With Page Numbers
`
              https://www.tripadvisor.com/Hotel_Review-g1224250-d305165-Reviews-or10-The_Siam.html
            `

### Different Domains
`
              https://www.tripadvisor.co.uk/Hotel_Review-g1224250-d305165-Reviews-The_Siam.html
            ``
              https://www.tripadvisor.de/Hotel_Review-g1224250-d305165-Reviews-The_Siam.html
            `

### Mobile URLs
`
              https://m.tripadvisor.com/Hotel_Review-g1224250-d305165-Reviews-The_Siam.html
            `

## Common Use Cases

- Preprocessing URLs before calling other TripAdvisor endpoints
- Building URL-to-ID mapping databases
- Validating TripAdvisor URLs in user input
- Extracting IDs from retrieved or collected URLs
- Converting between URL formats and location IDs

#### Batch Processing

When processing multiple URLs, extract all IDs first, then use the location-based endpoints for better performance.

Request

```curl
curl -X GET "https://api.stayapi.com/v1/tripadvisor/location/extract-id?url=https://www.tripadvisor.com/Hotel_Review-g1224250-d305165-Reviews-The_Siam.html" \
  -H "x-api-key: YOUR_API_KEY"
```

Response

```json
{
  "success": true,
  "data": {
    "location_id": "305165",
    "url": "https://www.tripadvisor.com/Hotel_Review-g1224250-d305165-Reviews-The_Siam.html"
  },
  "message": "Successfully extracted location ID",
  "retrieved_at": "2024-01-15T10:30:00Z"
}
```

```json
{
  "error": "Invalid URL format",
  "detail": "Could not extract location ID from URL. Please provide a valid TripAdvisor hotel URL.",
  "status_code": 400
}
```
