# Get Demand Surges

The Demand Surge API can be used to quickly scan a period of 90 days for abnormal increases in attendance for a given area. The API calculates the mean attendance for your requested location over the next 90 days after the `date_from` date and returns all the dates where attendance is a certain number of standard deviations over the mean. This is represented by the `min_surge_intensity` parameter, that corresponds to the number of standard deviations the API will look for.

Once you have identified the dates with the surge in demand, you can use:

* Our [Events API](/api/events/search-events.md) to find the names, descriptions, locations, and other details of the events that constitute the surges.
* Our [Features API](/api/features/get-features.md) to get Machine Learning features for events in your searched date range.

## GET /v1/demand-surge/

> Get Demand Surges

```json
{"openapi":"3.1.0","info":{"title":"PredictHQ Demand Surge API","version":"1.0.0"},"tags":[{"name":"Demand Surge API"}],"servers":[{"url":"https://api.predicthq.com"}],"security":[{"BearerAuth":[]}],"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"$API_KEY","description":"Enter your PredictHQ API key. The Bearer prefix is added automatically.\n\nWhen calling the API directly, send: `Authorization: Bearer <YOUR_API_KEY>` as documented at [https://docs.predicthq.com/api/overview/authenticating](https://docs.predicthq.com/api/overview/authenticating)\n"}},"schemas":{"SizeEnum":{"type":"string","enum":["s","m","l","xl"],"title":"SizeEnum"},"DemandSurgeResponse":{"type":"object","properties":{"count":{"description":"The number of identified demand surges given the search criteria.","type":"integer","title":"Count"},"surge_dates":{"description":"An array of identified demand surges.","type":"array","items":{"$ref":"#/components/schemas/SurgeDate"},"title":"Surge Dates"}},"required":["count"],"title":"DemandSurgeResponse"},"SurgeDate":{"type":"object","properties":{"date":{"description":"The date of the identified demand surge.","type":"string","format":"date","title":"Date"},"phq_attendance_sum":{"description":"The sum of all attendance based features in the identified demand surge.","type":"integer","title":"Phq Attendance Sum"}},"required":["date","phq_attendance_sum"],"title":"SurgeDate"},"HTTPValidationError":{"type":"object","properties":{"detail":{"type":"array","items":{"$ref":"#/components/schemas/ValidationError"},"title":"Detail"}},"title":"HTTPValidationError"},"ValidationError":{"type":"object","properties":{"loc":{"type":"array","items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/demand-surge/":{"get":{"operationId":"get_demand_surges","summary":"Get Demand Surges","parameters":[{"name":"min_surge_intensity","in":"query","description":"Filters out demand surges smaller than the minimum surge intensity provided.\n\n\nE.g. `?min_surge_intensity=m`","required":true,"schema":{"$ref":"#/components/schemas/SizeEnum"}},{"name":"date_from","in":"query","description":"The beginning of the demand surge search window. The demand surge will be looked up over the next 90 days after the date you provide for the `date_from` parameter.\n\n\nThe accepted format for this parameter is `YYYY-MM-DD`\n\n\nE.g. `?date_from=2021-05-12`","required":true,"schema":{"type":"string","format":"date","title":"Date From"}},{"name":"location.place_id","in":"query","description":"A comma-separated list in the format representing the place ids of a location in the format `<place_id1>,<place_id2>` . It cannot be used with `origin` or `radius` suffixes.\n\n\nE.g. `?location.place_id=2643743,2643744`","required":false,"schema":{"type":"array","items":{"type":"string"},"title":"Location.Place Id"},"explode":false,"style":"form"},{"name":"location.origin","in":"query","description":"A comma-separated coordinate (`<lat>,<lon>`) representing the centroid of a location. It must be used with `location.radius` and cannot be used with `location.place_id`.\n\n\nE.g. `?location.origin=40.7128,74.0060`","required":false,"schema":{"type":"array","items":{"type":"string"},"title":"Location.Origin"},"explode":false,"style":"form"},{"name":"location.radius","in":"query","description":"A string representing the `radius` for the demand surge, in the format `<radius_value><radius_unit>`, where `<radius_value>` is an integer or a float number up to 2 decimal places and `<radius_unit>` is one of:\n- `m` - meters\n- `km` - kilometers\n- `ft` - feet\n- `mi` - miles\n\n\nE.g. `?location.radius=100mi`","required":false,"schema":{"type":"string","title":"Location.Radius"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DemandSurgeResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"tags":["Demand Surge API"]}}}}
```

## OpenAPI Spec

The OpenAPI spec for Demand Surge API can be [found here](https://api.predicthq.com/docs/?urls.primaryName=Demand+Surge+API).

## Examples

{% tabs %}
{% tab title="curl" %}

```bash
curl -X GET "https://api.predicthq.com/v1/demand-surge/?date_from=2021-05-12&min_surge_intensity=m&location.place_id=2643743" \
     -H "Accept: application/json" \
     -H "Authorization: Bearer $ACCESS_TOKEN"
```

{% endtab %}

{% tab title="python" %}

```python
import requests

response = requests.get(
    url="https://api.predicthq.com/v1/demand-surge/",
    headers={
      "Authorization": "Bearer $ACCESS_TOKEN",
      "Accept": "application/json"
    },
    params={
        "date_from": "2021-05-12",
        "min_surge_intensity": "m",
        "location.place_id": "2643743"
    }
)

print(response.json())
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.predicthq.com/api/demand-surge/get-demand-surges.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
