# Traffic

`POST https://bemap.benomad.com/bgis/service/traffic/1.0`

Part of [Traffic](https://benomad.com/dev/doc/bemap-api/more-services/traffic.md).

> **Get live traffic.** The traffic events and conditions of a country or an area, to warn drivers or plan around them.

To get the traffic information by country or an restricted area.

Provisioned per account: without it, BeMap answers `400 Access Denied`.

## Request body

JSON, `Content-Type: application/json`. Schema `TrafficRequest`.

- `geoserver` (string): Geoserver name.
- `swidx` (integer (int32), deprecated): Switch index.
- `countryCode` (string): Country ISO Code. Performs a data extract operation inside the specified Iso code filter.
- `timestamp` (integer (int64)): Time stamp in milliseconds.
- `boundingBox` (BoundingBox): The bounding box make a filter on an specific area.
  - `minLon` (number (double)): Minimum longitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
  - `minLat` (number (double)): Minimum latitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
  - `maxLon` (number (double)): Maximum longitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
  - `maxLat` (number (double)): Maximum latitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
- `elementId` (string): Traffic element ID.
- `reverseDirection` (boolean): Define the side of road will be used.
- `options` (enum[]): Options of traffic info service.
  - `STATS`: Enable the data outputs like jam factor, speed and other information.
  - `POLYLINE`: Enable the polyline geometry output.
  - `SYNC`
  - `ALERTC`: Enable the Alert-C outputs.
  - `OPENLR`: Enable the OpenLR outputs.
  - `TRAFFIC_PREDICTIVE`: Enable the predictive traffic information.
  - `TRAFFIC_HISTORICAL`: (Beta) Enable the historical traffic information.
  - `ONLY_BLOCKED_ROAD`: To get only the blocked roads (closed).
  - `EXCLUDE_BLOCKED_ROAD`: To exclude all blocked roads (closed).
- `previousUpdateTimestamp` (integer (int64), deprecated): The previous time stamp of update, can be used for synchronization mode.
- `outputLanguage` (string): Output language.

## Response

`200`, schema `TrafficResponse`.

- `countryInitialized` (boolean): Country initialized.
- `trafficResponseElements` (TrafficRespElement[]): Traffic response elements.
  - `trafficItem` (TrafficItem): Traffic Item.
    - `info` (TrafficElementInfo): Traffic information of element.
      - `id` (string)
      - `countryCode` (string)
      - `copyright` (string)
      - `releaseDate` (string (date-time))
      - `lastUpdateDate` (string (date-time))
    - `elementId` (string): Element ID.
    - `reverseDirection` (boolean): True for inverse road direction.
    - `boundingBox` (BoundingBox): Bounding box of geometry in WGS84.
      - `minLon` (number (double)): Minimum longitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
      - `minLat` (number (double)): Minimum latitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
      - `maxLon` (number (double)): Maximum longitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
      - `maxLat` (number (double)): Maximum latitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
    - `jamFactor` (number (float)): Percent (%) of traffic jam. Between 0.00 (free way) to 100.00 (full jam).
    - `reason` (enum): TrafficReason.
      - `NA`: Not available.
      - `CONGESTION`: traffic congestion (jam).
      - `CARRIAGEWAY_REDUCED`: Carriage-way reduced.
      - `ACCIDENT`: Accident.
      - `INCIDENT`: Incident.
      - `INFORMATION`: Information.
      - `NON_RECOMMANDED_ROAD`: Non re-commanded road.
      - `ROAD_CONDITION_DETERIORATED`: Road condition deteriorated.
      - `BLOCKED_ROAD`: Blocked road.
      - `ROAD_UNDER_CONTRUCTION`: Road under construction.
    - `reasonComments` (TrafficResComment[]): List of reason comments.
      - `language` (string)
      - `comment` (string)
    - `reasonCoordinate` (Coordinate): Coordinate of the reason event.
      - `lon` (number (double), required): Longitude in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). Also accepted as `longitude`.
      - `lat` (number (double), required): Latitude in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). Also accepted as `latitude`.
    - `polyline` (Coordinate[]): Polyline.
      - `lon` (number (double), required): Longitude in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). Also accepted as `longitude`.
      - `lat` (number (double), required): Latitude in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). Also accepted as `latitude`.
    - `segmentInfos` (TrafficSegInfo[]): Segment Info.
      - `id` (string): Unique identifier of road segment.
      - `reverseDirection` (boolean): The route travel is in opposite way of geometry.
    - `tmcInternalId` (integer (int64)): AlertcTrafficElement.
    - `alertcEbuCountryCode` (string): AlertcTrafficElement.
    - `alertcTableId` (integer (int64)): AlertcTrafficElement.
    - `alertcLocationId` (integer (int64)): AlertcTrafficElement.
    - `alertcExtend` (integer (int32)): AlertcTrafficElement.
    - `alertcCode` (integer (int32)): AlertcTrafficElement.
    - `openLrBase64` (string): OpenLrTrafficElement.

## Errors

- `400`: Bad Request
- `302`: no credentials were sent. Do not follow the redirect.
- `401`: the account or the API key is wrong.

How to read each one: [Errors](https://benomad.com/dev/doc/bemap-api/getting-started/errors.md).

## Example

```bash
curl -X POST 'https://bemap.benomad.com/bgis/service/traffic/1.0' \
  -u 'YOUR_ACCOUNT:YOUR_API_KEY' \
  --fail-with-body \
  -H 'Content-Type: application/json' \
  -d '{
  "boundingBox": {
    "minLat": 48.8,
    "minLon": 2.25,
    "maxLat": 48.92,
    "maxLon": 2.42
  },
  "countryCode": "FRA",
  "outputLanguage": "fr",
  "options": [
    "POLYLINE"
  ]
}'
```

Response captured from production, long arrays and strings shortened:

```json
{
  "countryInitialized": true,
  "trafficResponseElements": [
    {
      "trafficItem": {
        "info": {
          "countryCode": "FRA",
          "copyright": "HERE",
          "releaseDate": 1790944338000,
          "lastUpdateDate": 1790944356323
        },
        "elementId": "520397642",
        "reverseDirection": false,
        "boundingBox": {
          "minLon": 2.36032,
          "minLat": 48.86191,
          "maxLon": 2.36461,
          "maxLat": 48.86426
        },
        "jamFactor": 51.360798,
        "reason": "NA",
        "reasonCoordinate": {
          "lon": 2.36032,
          "lat": 48.86426
        },
        "polyline": [
          {
            "lon": 2.36032,
            "lat": 48.86426
          },
          {
            "lon": 2.36052,
            "lat": 48.86412
          }
        ],
        "segmentInfos": [
          {
            "id": "4385172450468",
            "reverseDirection": true
          },
          {
            "id": "4385172503580",
            "reverseDirection": false
          }
        ],
        "tmcInternalId": 520397642,
        "alertcEbuCountryCode": "F",
        "alertcTableId": 32,
        "alertcLocationId": 41802,
        "alertcExtend": 0,
        "alertcCode": 115
      }
    },
    {
      "trafficItem": {
        "info": {
          "countryCode": "FRA",
          "copyright": "HERE",
          "releaseDate": 1790944338000,
          "lastUpdateDate": 1790944356323
        },
        "elementId": "520397639",
        "reverseDirection": false,
        "boundingBox": {
          "minLon": 2.36664,
          "minLat": 48.8558,
          "maxLon": 2.36849,
          "maxLat": 48.85605
        },
        "jamFactor": 83.087,
        "reason": "NA",
        "reasonCoordinate": {
          "lon": 2.36732,
          "lat": 48.85594
        },
        "polyline": [
          {
            "lon": 2.36732,
            "lat": 48.85594
          },
          {
            "lon": 2.36818,
            "lat": 48.8558
          }
        ],
        "segmentInfos": [
          {
            "id": "4385172502648",
            "reverseDirection": false
          },
          {
            "id": "4385172502799",
            "reverseDirection": false
          }
        ],
        "tmcInternalId": 520397639,
        "alertcEbuCountryCode": "F",
        "alertcTableId": 32,
        "alertcLocationId": 41799,
        "alertcExtend": 0,
        "alertcCode": 108
      }
    }
  ]
}
```

## Reference pages

- [Traffic](https://benomad.com/dev/doc/bemap-api/guides/services/traffic.md)
