Skip to main content
Version: v2.0

Getting started

Welcome to the ServiceNow SDK for Go! This guide helps you set up the SDK and make your first successful API call in just a few minutes.

Personalize the code samplesstays in your browser

Enter your instance details and every code sample in the docs renders with them instead of placeholders like {instance}. Values are stored only in this browser's localStorage — never sent anywhere. Don't enter a password; samples keep the {password} placeholder.

Prerequisites

Before you begin, make sure your development environment meets these requirements:

Install the SDK

Add the SDK to your existing Go module using the go get command:

go get github.com/michaeldcanady/servicenow-sdk-go/v2

Initialize the client

To interact with ServiceNow, you must first configure your credentials and initialize a client. The following example demonstrates a basic setup using username and password authentication.

import (
"log"

servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go/v2"
"github.com/michaeldcanady/servicenow-sdk-go/v2/credentials"
)

func main() {
// 1. Configure your credentials
credAdmin := credentials.NewBasicProvider("{username}", "{password}")

// 2. Initialize the client for your instance
clientPanic, err := servicenowsdkgo.NewServiceNowServiceClient(
servicenowsdkgo.WithAuthenticationProvider(credAdmin),
servicenowsdkgo.WithURL("https://{instance}.service-now.com"),
)
if err != nil {
panic(err)
}
}

Make your first request

Here is the complete program: it authenticates, lists records from a table, and prints each record's number field. Save it as main.go, replace the placeholder values, and run go run main.go.

package main

import (
"context"
"fmt"
"log"

servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go/v2"
"github.com/michaeldcanady/servicenow-sdk-go/v2/credentials"
)

func main() {
cred := credentials.NewBasicProvider("{username}", "{password}")
client, err := servicenowsdkgo.NewServiceNowServiceClient(
servicenowsdkgo.WithAuthenticationProvider(cred),
servicenowsdkgo.WithURL("https://{instance}.service-now.com"),
)
if err != nil {
log.Fatal(err)
}

ctx := context.Background()
response, err := client.Now().Table("{TableName}").Get(ctx, nil)
if err != nil {
log.Fatal(err)
}

results, err := response.GetResult()
if err != nil {
log.Fatal(err)
}

for _, record := range results {
num, _ := record.Get("number")
val, _ := num.GetValue()
strVal, _ := val.GetStringValue()
fmt.Printf("Incident: %s", *strVal)
}
}

See the Table Operations guide for more on what you can do with the response.

Next steps

Now that you have the basic setup, explore these topics to dive deeper:

  • Core Concepts: The five rules behind every request and response — read this before your second program.
  • Authentication Guide: Learn about OAuth2 and alternative credential types.
  • Table Operations: Master CRUD operations for ServiceNow records.
  • Attachments: Manage files associated with your records.
  • API Reference: Consult the detailed documentation for specific API modules.
Was this page helpful?