> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Mapbox

> Client-mode REST API connector for a curated Mapbox slice: forward geocoding and driving directions

Technical Preview

# Mapbox

Client-mode REST API connector for a curated Mapbox slice: forward geocoding and driving directions.

* Hub category: **Maps**.
* Base: `https://api.mapbox.com`

## Template reference

Generated from the shipped broker template `mapbox` (`-routeCode MAPBOX`). It lists every event the template defines.

### Auth

The template sets no auth header. Check the event headers below.

### Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Mapbox connector | no |
| `BaseUrl` | string | Mapbox base URL without trailing slash (e.g. [https://api.mapbox.com](https://api.mapbox.com)) | yes |

`BASE_ADDRESS` default: `https://api.mapbox.com`.

### Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Geocode` | GET | `/geocoding/v5/mapbox.places/{value.json.search_text}.json?access_token={value.json.api_token}` | `maps/mapbox/geocode` | `maps/mapbox/geocode/response` | `api_token`, `search_text` |
| `Directions` | GET | `/directions/v5/mapbox/driving/{value.json.coordinates}?access_token={value.json.api_token}` | `maps/mapbox/directions` | `maps/mapbox/directions/response` | `api_token`, `coordinates` |

### Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode MAPBOX"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE MapboxRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api.mapbox.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Geocode
        WITH SOURCE_TOPIC "maps/mapbox/geocode"
        WITH DESTINATION_TOPIC "maps/mapbox/geocode/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/geocoding/v5/mapbox.places/{value.json.search_text}.json?access_token={value.json.api_token}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT Directions
        WITH SOURCE_TOPIC "maps/mapbox/directions"
        WITH DESTINATION_TOPIC "maps/mapbox/directions/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/directions/v5/mapbox/driving/{value.json.coordinates}?access_token={value.json.api_token}"
        WITH HEADERS
            ADD "Accept" "application/json"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

### Usage example

Call `Geocode` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'maps/mapbox/geocode/response' &
mosquitto_pub -t 'maps/mapbox/geocode' -m '{"api_token": "<api_token>", "search_text": "<search_text>"}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.