StatusPage API: create incident specifying new status
Asked by Juanje Caballero:

In the documentation, it is shown how to define an array. But if I am not mistaken, in order to define the new status of a new incident I would need to use a map and I don't figure out how to do this.

From the documentation, how to define an array (components):

    // JSON{  "incident": {    "name": "test incident",    "components": ["8kbf7d35c070", "vtnh60py4yd7"]  }}// Form Encoded (using curl as an example):curl -X POST https://api.statuspage.io/v1/example \  -d "incident[name]=test incident" \  -d "incident[components][]=8kbf7d35c070" \  -d "incident[components][]=vtnh60py4yd7"

To create an incident and set the new status, I should define these (among others; name, etc):

* components: Map of status changes to apply to affected components
  * component_id: Map of status changes to apply to affected components ("operational" "under_maintenance" "degraded_performance" "partial_outage" "major_outage" "")
* component_ids: Array of strings. List of component_ids affected by this incident

Belo, my unsuccessful tries below:

```
-d "incident[component_ids][]=yxrqcr0kc3hx"  \
-d "incident[components][component_id][]={'yxrqcr0kc3hx' : 'major_outage'}"  
```

```
-d "incident[component_ids][]=yxrqcr0kc3hx" \
-d "incident[components][component_id][yxrqcr0kc3hx]=major_outage" 
```

```
-d "incident[component_ids][]=yxrqcr0kc3hx" \
-d "incident[components][component_id]['yxrqcr0kc3hx']=major_outage"
```

Please, any help will be welcome.

Thanks


Answers:
author: Juanje Caballero
body: I have just figured it out:

```
-d "incident[component_ids][]=yxrqcr0kc3hx" \
-d "incident[components][yxrqcr0kc3hx]=major_outage"
```

Now, it makes totally sense.

comments: author: David Bakkers
body: OK, I get it. You specify the ID of the component, then you specify what value you want that that component to be, based on its ID.

The REST API documentation on the vendor's website isn't exactly helpful or illustrative; it just provides a lump of JSON without much explanation. Providing a cURL example that's just a tiny snippet of what's shown in the JSON example doesn't help either.


author: TDC-IT
body: thank you


author: David Bakkers
body: From what I can understand on the [StatusRest API documentation page](https://developer.statuspage.io/#operation/postPagesPageIdIncidents), in the *Create an Incident* section, it looks like when you create an Incident, you can create a Component on the Incident Page and give that Component an ID in the form of some name as a string.

You don't seem to be able to set the value of that Component when the page is being created, rather you have to update the value of the new Component after the page has been created by doing a Component [PATCH request](https://developer.statuspage.io/#operation/patchPagesPageIdComponentsComponentId) and referring to it by its ID and the Page ID using the endpoint:

```
/pages/{page_id}/components/{component_id}
```

So, I'd say you create the Incident page with the Component on it, parse the ID of that page and the ID of the Component from the response, then submit a new request to update the Component's value on that page by submitting a new request.

comments: author: Juanje Caballero
body: No, the components already exist. And users want to create an incident because something is wrong in those existing components. As part of this reporting process or incident creation, users need to define the new status on the affected components. Otherwise, they stay with their default value: Operational. Hence, the effect is as no incident was created.

The explanations I posted of "components" and "component_ids" are not my words, it also comes from the [StatusPage API documentation - create incident](https://developer.statuspage.io/#operation/postPagesPageIdIncidents "StatusPage API documentation - create incident")

In my opinion, your proposal is a workaround but not the proper way to do it. With your proposal, all our customers would receive two notifications: one with the creation of the incident and another adjusting the status of the component in the new incident. There must be a way to add the map data in the curl command.


Tags: api

rest-api