Can you automatically resolve the affected components of a scheduled maintenace via the API?
Asked by Jon H:

Hi there,

When you create a scheduled maintenance via the Status Page UI, you have these automation options made available to you, notably the "set affected components' status to 'Under Maintenance'" and "set affected components' status to 'Operational" at the start time and end time of scheduled maintenances, respectively.  

![SP params.png](https://community.atlassian.com/t5/image/serverpage/image-id/194513i2591F0B94872A25A/image-size/large?v=v2&px=999 "SP params.png")  

I'd like to enable these [through the API](https://developer.statuspage.io/#operation/postPagesPageIdIncidents), but it doesn't seem possible. I see that there are two \`scheduled_auto_in_progress\` and \`scheduled_auto_completed\` params you can pass when creating/updating an incident, but this doesn't change any of the components' statuses.  

It seems that the affected components are set to \`under_maintenance\` immediately after you create the scheduled maintenance, even if the start time is far into the future. Additionally, these are not resolved after the scheduled maintenance is complete.

Is there a workaround for this, or perhaps something that I'm missing? Thank you!  

Edit: I see now that there is a \`auto_transition_to_maintenance_state\` and a \`auto_transition_to_operational_state\` parameter that can be passed when creating an incident. This seems to do what it suggests, but the component is still set to \`under_maintenance\` as soon as the scheduled maintenance is added, even if it is scheduled out weeks in advance. Is there a way to ensure that the component is only set to \`under_maintenance\` at the scheduled start time? The UI manages do this without issue.


Answers:
author: Scot Wilson
body: G'day Jon!  
I'm Scot from the APAC Statuspage Support Team.  

Could you check your JSON payload to see if you are setting "components" instead of "component_ids" ?  

If you are use "components" - you will be setting the status of those components when you create the schedule for the maintenance, as you need to supply a component status with each component. You would normally set these values when you are creating an incident with components in different statuses.  

```
"components": {
    "q43sx76mp7wj": "under_maintenance"
}
```

For a scheduled maintenance - you should just supply component_ids as that is the list of component_ids that will be affected by this maintenance, and the system will change the status for these components when the maintenance starts and ends.  

```
"component_ids": [
    "dndwh3z7qsjb"
]
```

<br />

This is an example of the JSON needed to create a scheduled maintenance that include the component with the ids of "change_me" and "also_me".  

```
{
    "incident": {
        "name":"Maintenance Scheduled for Later",
        "status": "scheduled",
        "impact_override": "maintenance",
        "scheduled_for": "2022-04-28T03:55:00.007Z",
        "scheduled_until": "2022-04-28T04:00:00.007Z",
        "scheduled_remind_prior": false,
        "scheduled_auto_in_progress": true,
        "scheduled_auto_completed": true,
        "metadata": { },
        "deliver_notifications": true,
        "auto_transition_deliver_notifications_at_end": true,
        "auto_transition_deliver_notifications_at_start": true,
        "auto_transition_to_maintenance_state": true,
        "auto_transition_to_operational_state": true,
        "body": "We are reticulating splines",
        "component_ids": [
                "change_me", "also_me"
        ]
    }
}
```

Hope that helps,  
Scot.

comments: author: Jon H
body: Thank you so much, this is a huge help! I was definitely providing them as a \`components\` object rather than a \`components_ids\` list. I'll play around with this now, but it seems to do exactly what I was hoping for. Thanks again!