Create a new SLO report

Note: This feature is in private beta. To request access, use the request access form in the Service Level Objectives docs.

POST https://api.ap1.datadoghq.com/api/v2/slo/reporthttps://api.ap2.datadoghq.com/api/v2/slo/reporthttps://api.datadoghq.eu/api/v2/slo/reporthttps://api.ddog-gov.com/api/v2/slo/reporthttps://api.us2.ddog-gov.com/api/v2/slo/reporthttps://api.datadoghq.com/api/v2/slo/reporthttps://api.us3.datadoghq.com/api/v2/slo/reporthttps://api.us5.datadoghq.com/api/v2/slo/report

Overview

Create a job to generate an SLO report. The report job is processed asynchronously and eventually results in a CSV report being available for download.

Check the status of the job and download the CSV report using the returned report_id.

This endpoint requires the slos_read permission.

OAuth apps require the slos_read authorization scope to access this endpoint.

Request

Body Data (required)

Create SLO report job request body.

Expand All

Field

Type

Description

data [required]

object

The data portion of the SLO report request.

attributes [required]

object

The attributes portion of the SLO report request.

from_ts [required]

int64

The from timestamp for the report in epoch seconds.

interval

enum

The frequency at which report data is to be generated. Allowed enum values: daily,weekly,monthly

query [required]

string

The query string used to filter SLO results. Some examples of queries include service:<service-name> and slo-name.

timezone

string

The timezone used to determine the start and end of each interval. For example, weekly intervals start at 12am on Sunday in the specified timezone.

to_ts [required]

int64

The to timestamp for the report in epoch seconds.

{
  "data": {
    "attributes": {
      "from_ts": 1633173071,
      "to_ts": 1636629071,
      "query": "slo_type:metric \"SLO Reporting Test\"",
      "interval": "monthly",
      "timezone": "America/New_York"
    }
  }
}

Response

OK

The SLO report response.

Expand All

Field

Type

Description

data

object

The data portion of the SLO report response.

id

string

The ID of the report job.

type

string

The type of ID.

{
  "data": {
    "id": "dc8d92aa-e0af-11ee-af21-1feeaccaa3a3",
    "type": "report_id"
  }
}

Bad Request

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Forbidden

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Code Example

                          ## default
# 

# Curl command
curl -X POST "https://api.ap1.datadoghq.com"https://api.ap2.datadoghq.com"https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.us2.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com"https://api.us5.datadoghq.com/api/v2/slo/report" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \ -d @- << EOF { "data": { "attributes": { "from_ts": 1690901870, "interval": "weekly", "query": "slo_type:metric", "timezone": "America/New_York", "to_ts": 1706803070 } } } EOF
// Create a new SLO report returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"time"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.SloReportCreateRequest{
		Data: datadogV2.SloReportCreateRequestData{
			Attributes: datadogV2.SloReportCreateRequestAttributes{
				FromTs:   time.Now().AddDate(0, 0, -40).Unix(),
				ToTs:     time.Now().Unix(),
				Query:    `slo_type:metric "SLO Reporting Test"`,
				Interval: datadogV2.SLOREPORTINTERVAL_MONTHLY.Ptr(),
				Timezone: datadog.PtrString("America/New_York"),
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.CreateSLOReportJob", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewServiceLevelObjectivesApi(apiClient)
	resp, r, err := api.CreateSLOReportJob(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `ServiceLevelObjectivesApi.CreateSLOReportJob`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `ServiceLevelObjectivesApi.CreateSLOReportJob`:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
// Create a new SLO report returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.ServiceLevelObjectivesApi;
import com.datadog.api.client.v2.model.SLOReportInterval;
import com.datadog.api.client.v2.model.SLOReportPostResponse;
import com.datadog.api.client.v2.model.SloReportCreateRequest;
import com.datadog.api.client.v2.model.SloReportCreateRequestAttributes;
import com.datadog.api.client.v2.model.SloReportCreateRequestData;
import java.time.OffsetDateTime;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setUnstableOperationEnabled("v2.createSLOReportJob", true);
    ServiceLevelObjectivesApi apiInstance = new ServiceLevelObjectivesApi(defaultClient);

    SloReportCreateRequest body =
        new SloReportCreateRequest()
            .data(
                new SloReportCreateRequestData()
                    .attributes(
                        new SloReportCreateRequestAttributes()
                            .fromTs(OffsetDateTime.now().plusDays(-40).toInstant().getEpochSecond())
                            .toTs(OffsetDateTime.now().toInstant().getEpochSecond())
                            .query("""
slo_type:metric "SLO Reporting Test"
""")
                            .interval(SLOReportInterval.MONTHLY)
                            .timezone("America/New_York")));

    try {
      SLOReportPostResponse result = apiInstance.createSLOReportJob(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ServiceLevelObjectivesApi#createSLOReportJob");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
"""
Create a new SLO report returns "OK" response
"""

from datetime import datetime
from dateutil.relativedelta import relativedelta
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.service_level_objectives_api import ServiceLevelObjectivesApi
from datadog_api_client.v2.model.slo_report_create_request import SloReportCreateRequest
from datadog_api_client.v2.model.slo_report_create_request_attributes import SloReportCreateRequestAttributes
from datadog_api_client.v2.model.slo_report_create_request_data import SloReportCreateRequestData
from datadog_api_client.v2.model.slo_report_interval import SLOReportInterval

body = SloReportCreateRequest(
    data=SloReportCreateRequestData(
        attributes=SloReportCreateRequestAttributes(
            from_ts=int((datetime.now() + relativedelta(days=-40)).timestamp()),
            to_ts=int(datetime.now().timestamp()),
            query='slo_type:metric "SLO Reporting Test"',
            interval=SLOReportInterval.MONTHLY,
            timezone="America/New_York",
        ),
    ),
)

configuration = Configuration()
configuration.unstable_operations["create_slo_report_job"] = True
with ApiClient(configuration) as api_client:
    api_instance = ServiceLevelObjectivesApi(api_client)
    response = api_instance.create_slo_report_job(body=body)

    print(response)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
# Create a new SLO report returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.unstable_operations["v2.create_slo_report_job".to_sym] = true
end
api_instance = DatadogAPIClient::V2::ServiceLevelObjectivesAPI.new

body = DatadogAPIClient::V2::SloReportCreateRequest.new({
  data: DatadogAPIClient::V2::SloReportCreateRequestData.new({
    attributes: DatadogAPIClient::V2::SloReportCreateRequestAttributes.new({
      from_ts: (Time.now + -40 * 86400).to_i,
      to_ts: Time.now.to_i,
      query: 'slo_type:metric "SLO Reporting Test"',
      interval: DatadogAPIClient::V2::SLOReportInterval::MONTHLY,
      timezone: "America/New_York",
    }),
  }),
})
p api_instance.create_slo_report_job(body)

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
// Create a new SLO report returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_service_level_objectives::ServiceLevelObjectivesAPI;
use datadog_api_client::datadogV2::model::SLOReportInterval;
use datadog_api_client::datadogV2::model::SloReportCreateRequest;
use datadog_api_client::datadogV2::model::SloReportCreateRequestAttributes;
use datadog_api_client::datadogV2::model::SloReportCreateRequestData;

#[tokio::main]
async fn main() {
    let body = SloReportCreateRequest::new(SloReportCreateRequestData::new(
        SloReportCreateRequestAttributes::new(
            1633173071,
            r#"slo_type:metric "SLO Reporting Test""#.to_string(),
            1636629071,
        )
        .interval(SLOReportInterval::MONTHLY)
        .timezone("America/New_York".to_string()),
    ));
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.CreateSLOReportJob", true);
    let api = ServiceLevelObjectivesAPI::with_config(configuration);
    let resp = api.create_slo_report_job(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
/**
 * Create a new SLO report returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
configuration.unstableOperations["v2.createSLOReportJob"] = true;
const apiInstance = new v2.ServiceLevelObjectivesApi(configuration);

const params: v2.ServiceLevelObjectivesApiCreateSLOReportJobRequest = {
  body: {
    data: {
      attributes: {
        fromTs: Math.round(
          new Date(new Date().getTime() + -40 * 86400 * 1000).getTime() / 1000
        ),
        toTs: Math.round(new Date().getTime() / 1000),
        query: `slo_type:metric "SLO Reporting Test"`,
        interval: "monthly",
        timezone: "America/New_York",
      },
    },
  },
};

apiInstance
  .createSLOReportJob(params)
  .then((data: v2.SLOReportPostResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));

Instructions

First install the library and its dependencies and then save the example to example.ts and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"