Skip to main content
Version: v2.0

Explore documents and versions

Search the Document Management workspace and list a document's versions.

When to use this pattern

  • You're integrating with ServiceNow Document Management (not record attachments — that's the Attachment API)
  • You need to find documents and folders, or audit a document's version history

Required values

ValueDescription
Document sys_idFor version operations: the document to inspect

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()

documents := client.Now().Documents()

// Step 2: Explore documents and folders
results, err := documents.Explore().Get(ctx, nil)
if err != nil {
log.Fatalf("explore failed: %v", err)
}
fmt.Printf("explore returned: %+v\n", results)

// Step 3: List a document's versions
versions, err := documents.Versions("{SysID}").Get(ctx, nil)
if err != nil {
log.Fatalf("versions failed: %v", err)
}
fmt.Printf("versions: %+v\n", versions)
}

Tips

  • Explore() supports filters, sorting, and pagination through its query parameters.
  • To download content, chain Content(documentSysID).Get(...) the same way as Versions.

Next steps

Was this page helpful?