Skip to main content
Version: v2.0

Read customer accounts

List the customer accounts visible to the integration user.

When to use this pattern

  • You're linking CSM cases or contacts to their owning accounts
  • You're exporting account data for CRM reconciliation

Required values

ValueDescription
Account filtersOptional query parameters narrowing which accounts you get

Example

package main

import (
"context"
"fmt"
"log"

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

func main() {
// Step 1: Authenticate and initialize the client
cred := credentials.NewBasicProvider("{username}", "{password}")

client, err := servicenow.NewServiceNowServiceClient(
servicenow.WithAuthenticationProvider(cred),
servicenow.WithInstance("{instance}"),
)
if err != nil {
log.Fatalf("failed to initialize client: %v", err)
}
ctx := context.Background()

// Step 2: List customer accounts
response, err := client.Now().Account().Get(ctx, nil)
if err != nil {
log.Fatalf("unable to list accounts: %v", err)
}

// Step 3: Read fields from each account
accounts, err := response.GetResult()
if err != nil {
log.Fatal(err)
}

for _, account := range accounts {
name, err := account.GetName()
if err != nil {
log.Fatal(err)
}
if name != nil {
fmt.Printf("Account: %s\n", *name)
}
}
}

Tips

  • The Account API is read-oriented; account records are managed in ServiceNow itself.
  • ByID(accountID) fetches one account by its account ID.

Next steps

Was this page helpful?