[ All integrations ](https://ohdear.app/third-party-integrations)

# API Examples

Collection of JavaScript/Node.js scripts demonstrating Oh Dear API usage for automation.

[ ohdearapp/ohdear-api-examples ](https://github.com/ohdearapp/ohdear-api-examples)

by [ Oh Dear ](https://ohdear.app)

## Oh Dear API Examples & Scripts [\#](#oh-dear-api-examples-amp-scripts)

This repository contains examples and quick scripts to help you get started with the Oh Dear API. It includes a mini JavaScript SDK and helper functions you can copy into your own projects.

## Use Cases [\#](#use-cases)

The Oh Dear API can be used in many workflows:

- **Deployment Scripts**: Start a named maintenance window during deployments to prevent false positive alerts, and update your status page automatically
- **GitHub Actions**: Add new client sites to monitoring or trigger Lighthouse reports when your marketing site is updated
- **Status Page Sync**: Automatically keep status pages in sync with tagged sites
- **Custom Reports**: Generate monthly report snapshots for white-labelled PDFs or emails

## Installation [\#](#installation)

```
<span class="hl-keyword">git</span> clone https://github.com/ohdearapp/ohdear-api-examples.git
<span class="hl-keyword">cd</span> ohdear-api-examples
<span class="hl-keyword">cp</span> .env.example .env
<span class="hl-keyword">npm</span> install
```

Add your API key to the `.env` file:

```
OH_DEAR_API_KEY=your-api-key
```

## Example: Create Site From Template [\#](#example-create-site-from-template)

```
<span class="hl-keyword">import</span> { create_site_from_existing } <span class="hl-keyword">from</span> <span class="hl-value">'./examples.js'</span>;

<span class="hl-comment">// Create a new site using site ID 5746 as template for team 17</span>
<span class="hl-property">create_site_from_existing</span>(17, 5746);
```

## Example: Sync Status Pages [\#](#example-sync-status-pages)

```
<span class="hl-keyword">import</span> { sync_status_pages_with_tagged_sites } <span class="hl-keyword">from</span> <span class="hl-value">'./examples.js'</span>;

<span class="hl-comment">// Sync status pages with sites tagged 'production'</span>
<span class="hl-property">sync_status_pages_with_tagged_sites</span>(<span class="hl-value">'production'</span>);
```

Almost everything you can do in the Oh Dear application can also be done via the API. Check the [API documentation](https://ohdear.app/docs/integrations/the-oh-dear-api) for more details.
