# Update an Analysis

## Update an Analysis

> Update (replace) an existing Analysis.\
> \
> This endpoint accepts the same request body fields as the Create an Analysis endpoint.\
> \
> Remember this is a PUT endpoint which means you must provide all supported fields or you may lose data - you are\
> effectively replacing the existing record with a new record containing all the fields you provide.\
> We recommend first getting the existing record and pre-populating the request body with the current values,\
> then change the fields you need to change.\
> \
> If you wish to update a smaller number of fields please use the PATCH endpoint.

```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"},"HTTPError":{"type":"object","properties":{"error":{"type":"string","title":"Error"}},"required":["error"],"title":"HTTPError"},"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"}}},"paths":{"/v1/beam/analyses/{analysis_id}":{"put":{"operationId":"put_analysis_public_analyses__analysis_id__put","summary":"Update an Analysis","description":"Update (replace) an existing Analysis.\n\nThis endpoint accepts the same request body fields as the Create an Analysis endpoint.\n\nRemember this is a PUT endpoint which means you must provide all supported fields or you may lose data - you are\neffectively replacing the existing record with a new record containing all the fields you provide.\nWe recommend first getting the existing record and pre-populating the request body with the current values,\nthen change the fields you need to change.\n\nIf you wish to update a smaller number of fields please use the PATCH endpoint.","parameters":[{"name":"analysis_id","in":"path","description":"An existing Beam Analysis ID.","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PutAnalysisRequest"}}}},"responses":{"204":{"description":"Successful Response"},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/HTTPError"},{"$ref":"#/components/schemas/ValidationError"}]}}}},"403":{"description":"Bearer token scope insufficient"},"404":{"description":"Analysis not found"},"409":{"description":"A data conflict has occurred due to the analysis being modified elsewhere. Please retry your call later."}},"tags":["Analyses"]}}}}
```

## Examples

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

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

{% endtab %}

{% tab title="python" %}

```python
import requests

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

print(response.status_code)
```

{% 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)
