# Create an Analysis

## Create an Analysis

> Creating an Analysis is the first step in understanding which types of events impact your demand.

```json
{"openapi":"3.1.0","info":{"title":"PredictHQ Beam API","version":"1.0.0"},"tags":[{"name":"Analyses"}],"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":{"PutAnalysisRequest":{"type":"object","properties":{"name":{"description":"Name of an analysis.","type":"string","minLength":1,"title":"Name"},"location":{"$ref":"#/components/schemas/Location"},"demand_type":{"$ref":"#/components/schemas/DemandType"},"external_id":{"description":"External identifier associated with the Analysis (optional, user-defined).","type":"string","minLength":1,"title":"External Id"},"label":{"description":"Comma-separated list of labels that can be used to search and filter analyses.","type":"array","items":{"type":"string","minLength":1},"explode":false,"minItems":1,"style":"form","title":"Label"},"rank":{"$ref":"#/components/schemas/Rank"}},"additionalProperties":false,"required":["name","location"],"title":"PutAnalysisRequest"},"Location":{"description":"Location of the Analysis.\n\nSupports one of the following location options:\n  - `saved_location_id`\n  - `geopoint` with `radius` and `unit`","type":"object","properties":{"geopoint":{"$ref":"#/components/schemas/GeoPoint"},"radius":{"description":"Must be an integer or a float number up to 2 decimal places. It represents the radius of the event search around\nyour `geopoint` to use for time series modelling and correlation. We **strongly recommend** using the\n[Suggested Radius API](https://docs.predicthq.com/api/suggested-radius/get-suggested-radius) to find a\nsuitable radius for your location/industry.","type":"number","exclusiveMinimum":0,"title":"Radius"},"unit":{"description":"The unit for `radius` where\n  - `m` is meters\n  - `km` is kilometers\n  - `ft` is feet\n  - `mi` is miles","type":"string","enum":["m","mi","km","ft"],"title":"Unit"},"saved_location_id":{"description":"The ID of a previously created Saved Location for your analysis as documented at\n[Saved Locations API](https://docs.predicthq.com/api/saved-locations/create-a-saved-location)","type":"string","minLength":1,"title":"Saved Location Id"}},"title":"Location"},"GeoPoint":{"description":"Contains `lat` and `lon` coordinates for your analysis, e.g. if you are creating an analysis for a store in\nSeattle you'd specify the latitude and longitude of your store.","type":"object","properties":{"lat":{"type":"string","pattern":"^[-+]?(90(\\.0+)?|([1-8]\\d|[1-9])(\\.\\d+)?|0+\\.(\\d+)?[1-9]+(\\d+)?)$","title":"Lat"},"lon":{"type":"string","pattern":"^[-+]?(180(\\.0+)?|(1[0-7]\\d|\\d\\d|[1-9])(\\.\\d+)?|0+\\.(\\d+)?[1-9]+(\\d+)?)$","title":"Lon"}},"required":["lat","lon"],"title":"GeoPoint"},"DemandType":{"description":"Provides information about the demand type of the analysis.","type":"object","properties":{"industry":{"$ref":"#/components/schemas/Industry"},"interval":{"default":"day","$ref":"#/components/schemas/Interval"},"week_start_day":{"$ref":"#/components/schemas/Weekday"},"unit_descriptor":{"description":"The description of the unit of demand, which specifies the type or measure being quantified (e.g.,\n\"Occupancy Rate\", \"Sales\", \"Number of Transactions\").","type":"string","default":"Sales","title":"Unit Descriptor"},"currency_code":{"default":"USD","$ref":"#/components/schemas/CurrencyCode"},"unit_currency_multiplier":{"description":"The multiplier used to adjust the unit of demand to its equivalent value in the specified currency.","type":"number","default":1,"exclusiveMinimum":0,"title":"Unit Currency Multiplier"}},"title":"DemandType"},"Industry":{"description":"The industry of the demand data being analysed by Beam. Choosing the right industry is important as this will\ndetermine the type of features used in the Analysis and will impact the accuracy of the results.","type":"string","default":"other","enum":["accommodation","cpg","tourism","marketing","parking","restaurants","retail","transportation","other"],"title":"Industry"},"Interval":{"type":"string","enum":["day","week"],"title":"Interval"},"Weekday":{"type":"string","enum":["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],"title":"Weekday"},"CurrencyCode":{"description":"The ISO 4217 standard code representing the currency corresponding to the units of demand.","type":"string","default":"USD","enum":["USD","EUR","GBP","AUD","CAD"],"title":"CurrencyCode"},"Rank":{"description":"Specifies which rank type to use when calculating event impacts and anomaly detection.\n\nOptionally, specify the minimum rank level to use when calculating event impacts.\n**We strongly recommend** not setting the rank levels and instead letting Beam define the best rank levels\nbased on your industry.","type":"object","properties":{"type":{"$ref":"#/components/schemas/RankType"},"levels":{"$ref":"#/components/schemas/RankLevels"}},"required":["type"],"title":"Rank"},"RankType":{"type":"string","enum":["phq","local"],"title":"RankType"},"RankLevels":{"type":"object","properties":{"phq":{"$ref":"#/components/schemas/RankLevel"},"local":{"$ref":"#/components/schemas/RankLevel"}},"additionalProperties":false,"title":"RankLevels"},"RankLevel":{"type":"object","properties":{"min":{"type":"integer","maximum":100,"minimum":0,"title":"Min"},"max":{"type":"integer","maximum":100,"minimum":0,"title":"Max"}},"required":["min"],"title":"RankLevel"},"AnalysisIdResponse":{"type":"object","properties":{"analysis_id":{"type":"string","title":"Analysis Id"}},"title":"AnalysisIdResponse"},"ValidationError":{"type":"object","properties":{"field":{"type":"array","items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"required":["field","msg","type"],"title":"ValidationError"},"HTTPError":{"type":"object","properties":{"error":{"type":"string","title":"Error"}},"required":["error"],"title":"HTTPError"}}},"paths":{"/v1/beam/analyses":{"post":{"operationId":"create_analysis_public_analyses_post","summary":"Create an Analysis","description":"Creating an Analysis is the first step in understanding which types of events impact your demand.","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PutAnalysisRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalysisIdResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/ValidationError"},{"$ref":"#/components/schemas/HTTPError"}]}}}}},"tags":["Analyses"]}}}}
```

## Examples

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

```bash
curl -X POST "https://api.predicthq.com/v1/beam/analyses" \
     -H "Accept: application/json" \
     -H "Authorization: Bearer $ACCESS_TOKEN" \
     --data @<(cat <<EOF
    {
        "name": "Analysis 1",
        "location": {
            "geopoint": {
                "lat": "-36.849761",
                "lon": "174.7628903"
            },
            "radius": 1.2,
            "unit": "km"
        },
        "demand_type": {
            "industry": "restaurants"
        },
        "rank": {
            "type": "phq"
        }
    }
    EOF
    )
```

{% endtab %}

{% tab title="python" %}

```python
import requests

response = requests.post(
    url="https://api.predicthq.com/v1/beam/analyses",
    headers={
        "Authorization": "Bearer $ACCESS_TOKEN",
        "Accept": "application/json"
    },
    json={
        "name": "Analysis 1",
        "location": {
            "geopoint": {
                "lat": "-36.849761",
                "lon": "174.7628903"
            },
            "radius": 1.2,
            "unit": "km"
        },
        "demand_type": {
            "industry": "restaurants"
        },
        "rank": {
            "type": "phq"
        }
    }
)

print(response.json())
```

{% endtab %}
{% endtabs %}

## OpenAPI Spec

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

## Guides

Below are some guides relevant to this API:

* [Beam Guides](https://app.gitbook.com/s/tNhzHETmXsrWeVBndqqJ/getting-started/guides/beam-guides)
