For AI agents: A markdown version of this page is available at https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/es/api/latest/service-level-objectives/create-an-slo-object.md. A documentation index is available at /llms.txt.
Language
Datadog site

Crear un objeto SLO

POSThttps://api.datadoghq.com/api/v1/slohttps://api.us3.datadoghq.com/api/v1/slohttps://api.us5.datadoghq.com/api/v1/slohttps://api.datadoghq.eu/api/v1/slohttps://api.ap1.datadoghq.com/api/v1/slohttps://api.ap2.datadoghq.com/api/v1/slohttps://api.uk1.datadoghq.com/api/v1/slohttps://api.ddog-gov.com/api/v1/slohttps://api.us2.ddog-gov.com/api/v1/slo

Descripción general

Crea un objeto objetivo de nivel de servicio (SLO).

This endpoint requires the slos_write permission.

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

Solicitud

Body Data (required)

Objeto de solicitud de objetivos de nivel de servicio.

Campo
Type
Descripción
description
string

Un objeto de solicitud de objetivo de nivel de servicio incluye un indicador de nivel servicio, umbrales para uno o varios periodos de tiempo y metadatos (nombre, descripción, etiquetas, etc.).

groups
[string]

A list of (up to 100) monitor groups that narrow the scope of a monitor service level objective.

Included in service level objective responses if it is not empty. Optional in create/update requests for monitor service level objectives, but may only be used when then length of the monitor_ids field is one.

monitor_ids
[integer]

A list of monitor IDs that defines the scope of a monitor service level objective. Required if type is monitor.

name [required]
string

The name of the service level objective object.

query
object

A count-based (metric) SLO query. This field is superseded by sli_specification but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or min of all of those requests.

sli_specification
<oneOf>

A generic SLI specification. This is used for time-slice and count-based (metric) SLOs only.

tags
[string]

A list of tags associated with this service level objective. Always included in service level objective responses (but may be empty). Optional in create/update requests.

target_threshold
double

The target threshold such that when the service level indicator is above this threshold over the given timeframe, the objective is being met.

thresholds [required]
[object]

The thresholds (timeframes and associated targets) for this service level objective object.

timeframe
enum

The SLO time window options. Note that "custom" is not a valid option for creating or updating SLOs. It is only used when querying SLO history over custom timeframes.

Allowed enum values: 7d, 30d, 90d, custom
type [required]
enum

The type of the service level objective.

Allowed enum values: metric, monitor, time_slice
warning_threshold
double

The optional warning threshold such that when the service level indicator is below this value for the given threshold, but above the target threshold, the objective appears in a "warning" state. This value must be greater than the target threshold.

Respuesta

OK

A response with one or more service level objective.

Campo
Type
Descripción
data
[object]

An array of service level objective objects.

errors
[string]

An array of error messages. Each endpoint documents how/whether this field is used.

metadata
object

The metadata object containing additional information about the list of SLOs.

Ejemplo de código

Create a new metric SLO object using bad events formula returns "OK" response
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "bad_events_formula": {
        "formula": "query2"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
Create a new metric SLO object using sli_specification returns "OK" response
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "metric",
  "description": "Metric SLO using sli_specification",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "count": {
      "good_events_formula": {
        "formula": "query1 - query2"
      },
      "total_events_formula": {
        "formula": "query1"
      },
      "queries": [
        {
          "data_source": "metrics",
          "name": "query1",
          "query": "sum:httpservice.hits{*}.as_count()"
        },
        {
          "data_source": "metrics",
          "name": "query2",
          "query": "sum:httpservice.errors{*}.as_count()"
        }
      ]
    }
  },
  "tags": [
    "env:prod",
    "type:count"
  ],
  "thresholds": [
    {
      "target": 99.0,
      "target_display": "99.0",
      "timeframe": "7d",
      "warning": 99.5,
      "warning_display": "99.5"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 99.0,
  "warning_threshold": 99.5
}
EOF
Create a time-slice SLO object returns "OK" response
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v1/slo" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "type": "time_slice",
  "description": "string",
  "name": "Example-Service-Level-Objective",
  "sli_specification": {
    "time_slice": {
      "query": {
        "formulas": [
          {
            "formula": "query1"
          }
        ],
        "queries": [
          {
            "data_source": "metrics",
            "name": "query1",
            "query": "trace.servlet.request{env:prod}"
          }
        ]
      },
      "comparator": ">",
      "threshold": 5
    }
  },
  "tags": [
    "env:prod"
  ],
  "thresholds": [
    {
      "target": 97.0,
      "target_display": "97.0",
      "timeframe": "7d",
      "warning": 98,
      "warning_display": "98.0"
    }
  ],
  "timeframe": "7d",
  "target_threshold": 97.0,
  "warning_threshold": 98
}
EOF