Skip to main content

Quick Start

This guide takes a client from nothing to a working monitor. It assumes you have installed an SDK and know how to create a client. You will list the uptime checks in your account, then create one, read it back and delete it.

List Uptime Checks​

With the API client configured you may make requests to the StatusCake API using the available methods. In this section we will list all uptime checks for the given workspace.

List Uptime Checks
package main

import (
"context"
"fmt"

"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)

func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(statuscake.WithRequestCredentials(bearer))

res, err := client.ListUptimeTests(context.Background()).Execute()
if err != nil {
panic(err)
}

fmt.Printf("%+v\n", res.Data)
}

Create, Read and Delete a Check​

A request is built by chaining the parameters you want onto the call, and sent with Execute. The remainder of this guide, and those that follow, use Go.

Create, read and delete an uptime check
package main

import (
"context"
"fmt"

"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)

func main() {
ctx := context.Background()

bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(statuscake.WithRequestCredentials(bearer))

created, err := client.CreateUptimeTest(ctx).
Name("statuscake.com").
TestType(statuscake.UptimeTestTypeHTTP).
WebsiteURL("https://www.statuscake.com").
CheckRate(statuscake.UptimeTestCheckRateFiveMinutes).
Execute()
if err != nil {
panic(err)
}

id := created.Data.NewID
fmt.Println("created check", id)

check, err := client.GetUptimeTest(ctx, id).Execute()
if err != nil {
panic(err)
}
fmt.Printf("%s checks %s every %d seconds\n", check.Data.Name, check.Data.WebsiteURL, check.Data.CheckRate)

if err := client.DeleteUptimeTest(ctx, id).Execute(); err != nil {
panic(err)
}
}

A few things to notice:

  • Every call takes a context.Context, which controls cancellation and deadlines.
  • Creating returns the identifier of the new check in Data.NewID. Identifiers are strings, and are what you pass to every other call about that check.
  • Updating and deleting return only an error, since the API returns no body.
  • Required parameters are checked before the request is made. Leave one out and Execute returns an error without contacting the API.

Next Steps​

The Managing Resources guide covers every kind of resource, and the Reading Results guide shows what a check has recorded.