Skip to content

solarwinds/squadcast-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Incident Response SDK for Go

Developer-friendly & type-safe Go SDK specifically catered to leverage Incident Response API.

Built by Speakeasy License: MIT

Summary

The Squadcast API provides developers the capability to extend and utilize Squadcast in conjunction with other services. Our API has resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.

Note: Customers using the V2 version of the Squadcast API would need to migrate to Squadcast API V3, as the former would be deprecated shortly.

Service Regions

Squadcast allows customers to choose the geographic region of the Squadcast data centers that host their account. When signing up, you can choose the service region. Currently, the available options are the United States (US) and Europe (EU).

Service Region API Endpoints
US Authentication: https://auth.squadcast.com · Other APIs: https://api.squadcast.com
EU Authentication: https://auth.eu.squadcast.com · Other APIs: https://api.eu.squadcast.com

Authentication

In order to access the API programmatically, HTTP bearer authentication needs to be used. HTTP bearer authentication must be constructed using an access_token, passed as the Authorization header for each request, for example Authorization: Bearer eyJleHAiOjE2MzU1OTE1OTIsImp0aSI6Im.

Steps to procure the access_token:

  1. Generate a refresh_token (API Token) from the Squadcast web app. More details on how to get the refresh_token can be found in the Squadcast support documentation.
  2. Call the authentication API with the refresh_token to obtain an access_token.
  3. Use the access_token as a Bearer token in the Authorization header for all subsequent API requests.

Example — Generating an Access Token

curl --location --request GET 'https://auth.squadcast.com/oauth/access-token' \
--header 'X-Refresh-Token: 0d2a1a9a454dxxxxxxxxxxxx'

The API response will look similar to:

{
  "data": {
    "access_token": "eyJhbGciOiJIUxxxxx.xxxxxxxxxxxxxxx.xxxxxxxxxxxxxxx",
    "expires_at": 1587412870,
    "issued_at": 1587240070,
    "refresh_token": "0d2a1a9a454dxxxxxxxxxxxx",
    "type": "bearer"
  }
}

Access Control

There are three different types of user roles in Squadcast: account_owner, stakeholder, and user. Refresh tokens upon creation are mapped with one of the mentioned user roles, and access to different resources is dependent on the permissions granted to these roles. For more information, please refer to the Squadcast support documentation.

Authorization

The access token authorizes users the ability to access different APIs, based on the user roles described above. Pass the access token as a Bearer token in the Authorization header of every request.

Table of Contents

SDK Installation

To add the SDK as a dependency to your project:

go get github.com/solarwinds/squadcast-sdk-go

SDK Example Usage

Example

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.Object != nil {
		// handle response
	}
}

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme Environment Variable
RefreshTokenAuth http Custom HTTP SQUADCASTSDK_REFRESH_TOKEN_AUTH

You can configure it using the WithSecurity option when initializing the SDK client instance. For example:

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.Object != nil {
		// handle response
	}
}

Available Resources and Operations

Available methods
  • List - Get All Tokens
  • List - List all Audit Logs
  • Export - Initiate an asynchronous export of audit logs based on the provided filters. The export file will be generated and available for download. Use 'Get details of Audit Logs export history by ID' API to retrieve the download URL.
  • ListExportHistory - List all Audit Logs export history
  • GetExportHistoryByID - Get details of Audit Logs export history by ID
  • GetByID - Get audit log by ID
  • GetByTeam - Get Escalation Policy By team
  • Create - Create Escalation Policies
  • Remove - Remove Escalation Policy
  • GetByID - Get Escalation Policy By ID
  • Update - Update Escalation Policy
  • Delete - Delete Global Oncall Reminder Rules
  • List - Get Global Oncall Reminder Rules
  • Create - Create Global Oncall Reminder Rules
  • Update - Update Global Oncall Reminder Rules
  • Rebuild - Rebuild a Project In CircleCI
  • Get - Get Additional Responders
  • Add - Add Additional Responders
  • Delete - Remove Additional Responders
  • Update - Update Communication Card
  • GetAll - Get All Communication Card
  • Create - Create Communication Card
  • Delete - Delete Communication Card
  • List - Get Incident Events
  • Snooze - Snooze Incident Notifications
  • List - Get All Notes
  • List - List Overrides
  • Delete - Delete Schedule Override
  • List - List Schedule Rotations
  • Get - Get Deduplication Rules
  • CreateOrUpdate - Create or Update Deduplication Rules
  • Render - Render Custom Content Overlay
  • Render - Render Dedup Key template
  • Delete - Delete Dedup Key Overlay
  • Get - Get Suppression Rules
  • Get - Get Tagging Rules
  • List - List Component Groups
  • Create - Create Component Group
  • DeleteByID - Delete Component Group By ID
  • GetByID - Get Component Group By ID
  • List - List Subscribers
  • GetAll - Get All Team Members

Pagination

Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will have a Next method that can be called to pull down the next group of results. If the return value of Next is nil, then there are no more pages to be fetched.

Here's an example of one such pagination call:

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"github.com/solarwinds/squadcast-sdk-go/models/operations"
	"github.com/solarwinds/squadcast-sdk-go/types"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.AuditLogs.List(ctx, operations.AuditLogsListAuditLogsRequest{
		PageSize:   832442,
		PageNumber: 555332,
		StartDate:  types.MustDateFromString("2023-03-04"),
		EndDate:    types.MustDateFromString("2024-08-07"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.V3AuditLogsListAuditLogsResponse != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retry.Config object to the call by using the WithRetries option:

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"github.com/solarwinds/squadcast-sdk-go/retry"
	"log"
	"models/operations"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil, operations.WithRetries(
		retry.Config{
			Strategy: "backoff",
			Backoff: &retry.BackoffStrategy{
				InitialInterval: 1,
				MaxInterval:     50,
				Exponent:        1.1,
				MaxElapsedTime:  100,
			},
			RetryConnectionErrors: false,
		}))
	if err != nil {
		log.Fatal(err)
	}
	if res.Object != nil {
		// handle response
	}
}

If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig option at SDK initialization:

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"github.com/solarwinds/squadcast-sdk-go/retry"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithRetryConfig(
			retry.Config{
				Strategy: "backoff",
				Backoff: &retry.BackoffStrategy{
					InitialInterval: 1,
					MaxInterval:     50,
					Exponent:        1.1,
					MaxElapsedTime:  100,
				},
				RetryConnectionErrors: false,
			}),
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.Object != nil {
		// handle response
	}
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.

By Default, an API error will return apierrors.APIError. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.

For example, the GetOrganization function may return the following errors:

Error Type Status Code Content Type
apierrors.BadRequestError 400 application/json
apierrors.UnauthorizedError 401 application/json
apierrors.PaymentRequiredError 402 application/json
apierrors.ForbiddenError 403 application/json
apierrors.NotFoundError 404 application/json
apierrors.ConflictError 409 application/json
apierrors.UnprocessableEntityError 422 application/json
apierrors.InternalServerError 500 application/json
apierrors.BadGatewayError 502 application/json
apierrors.ServiceUnavailableError 503 application/json
apierrors.GatewayTimeoutError 504 application/json
apierrors.APIError 4XX, 5XX */*

Example

package main

import (
	"context"
	"errors"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"github.com/solarwinds/squadcast-sdk-go/models/apierrors"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil)
	if err != nil {

		var e *apierrors.BadRequestError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.UnauthorizedError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.PaymentRequiredError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.ForbiddenError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.NotFoundError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.ConflictError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.UnprocessableEntityError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.InternalServerError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.BadGatewayError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.ServiceUnavailableError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.GatewayTimeoutError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.APIError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Select Server by Index

You can override the default server globally using the WithServerIndex(serverIndex int) option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Description
0 https://api.squadcast.com production US env
1 https://api.eu.squadcast.com production EU env

Example

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithServerIndex(0),
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.Object != nil {
		// handle response
	}
}

Override Server URL Per-Client

The default server can also be overridden globally using the WithServerURL(serverURL string) option when initializing the SDK client instance. For example:

package main

import (
	"context"
	squadcastsdk "github.com/solarwinds/squadcast-sdk-go"
	"log"
	"os"
)

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

	s := squadcastsdk.New(
		squadcastsdk.WithServerURL("https://api.eu.squadcast.com"),
		squadcastsdk.WithSecurity(os.Getenv("SQUADCASTSDK_REFRESH_TOKEN_AUTH")),
	)

	res, err := s.Analytics.GetOrganization(ctx, "<value>", "<value>", nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.Object != nil {
		// handle response
	}
}

Custom HTTP Client

The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

The built-in net/http client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.

import (
	"net/http"
	"time"

	"github.com/solarwinds/squadcast-sdk-go"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = squadcastsdk.New(squadcastsdk.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

Special Types

This SDK defines the following custom types to assist with marshalling and unmarshalling data.

Date

types.Date is a wrapper around time.Time that allows for JSON marshaling a date string formatted as "2006-01-02".

Usage

d1 := types.NewDate(time.Now()) // returns *types.Date

d2 := types.DateFromTime(time.Now()) // returns types.Date

d3, err := types.NewDateFromString("2019-01-01") // returns *types.Date, error

d4, err := types.DateFromString("2019-01-01") // returns types.Date, error

d5 := types.MustNewDateFromString("2019-01-01") // returns *types.Date and panics on error

d6 := types.MustDateFromString("2019-01-01") // returns types.Date and panics on error

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created by Speakeasy

<style> :root { --badge-gray-bg: #f3f4f6; --badge-gray-border: #d1d5db; --badge-gray-text: #374151; --badge-blue-bg: #eff6ff; --badge-blue-border: #3b82f6; --badge-blue-text: #3b82f6; } @media (prefers-color-scheme: dark) { :root { --badge-gray-bg: #374151; --badge-gray-border: #4b5563; --badge-gray-text: #f3f4f6; --badge-blue-bg: #1e3a8a; --badge-blue-border: #3b82f6; --badge-blue-text: #93c5fd; } } h1 { border-bottom: none !important; margin-bottom: 4px; margin-top: 0; letter-spacing: 0.5px; font-weight: 600; } .badge-text { letter-spacing: 1px; font-weight: 300; } .badge-container { display: inline-flex; align-items: center; background: var(--badge-gray-bg); border: 1px solid var(--badge-gray-border); border-radius: 6px; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 11px; text-decoration: none; vertical-align: middle; } .badge-container.blue { background: var(--badge-blue-bg); border-color: var(--badge-blue-border); } .badge-icon-section { padding: 4px 8px; border-right: 1px solid var(--badge-gray-border); display: flex; align-items: center; } .badge-text-section { padding: 4px 10px; color: var(--badge-gray-text); font-weight: 400; } .badge-container.blue .badge-text-section { color: var(--badge-blue-text); } .badge-link { text-decoration: none; margin-left: 8px; display: inline-flex; vertical-align: middle; } .badge-link:hover { text-decoration: none; } .badge-link:first-child { margin-left: 0; } .badge-icon-section svg { color: var(--badge-gray-text); } .badge-container.blue .badge-icon-section svg { color: var(--badge-blue-text); } </style>

About

Developer-friendly & type-safe Go SDK specifically catered to leverage Squadcast API

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages