Get attachment file
Overview
Retrieves an attachment's file data by sys id.
Path parameters
| Name | Description |
|---|---|
sysId | The sys id of the attachment. |
Optional query parameters
N/A
Required query parameters
N/A
Examples
- Fluent
- Standard
package main
import (
"context"
"fmt"
"log"
"os"
servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go/v2"
attachmentapi "github.com/michaeldcanady/servicenow-sdk-go/v2/attachmentapi"
"github.com/michaeldcanady/servicenow-sdk-go/v2/credentials"
abstractions "github.com/microsoft/kiota-abstractions-go"
)
func main() {
// Step 1: Create credentials
cred := credentials.NewBasicProvider("{username}", "{password}")
// Step 2: Initialize client
client, err := servicenowsdkgo.NewServiceNowServiceClient(
servicenowsdkgo.WithAuthenticationProvider(cred),
servicenowsdkgo.WithURL("https://{instance}.service-now.com"),
)
if err != nil {
log.Fatal(err)
}
fileGetConfig := &attachmentapi.AttachmentItemFileRequestBuilderGetRequestConfiguration{
// Optional configurations
}
fileGetResponse, err := client.Now().Attachment().ByID("{SysID}").File().Get(context.Background(), fileGetConfig)
if err != nil {
log.Fatal(err)
}
}
package main
import (
"context"
"fmt"
"log"
"os"
servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go/v2"
attachmentapi "github.com/michaeldcanady/servicenow-sdk-go/v2/attachmentapi"
"github.com/michaeldcanady/servicenow-sdk-go/v2/credentials"
abstractions "github.com/microsoft/kiota-abstractions-go"
)
func main() {
// Step 1: Create credentials
cred := credentials.NewBasicProvider("{username}", "{password}")
// Step 2: Initialize client
client, err := servicenowsdkgo.NewServiceNowServiceClient(
servicenowsdkgo.WithAuthenticationProvider(cred),
servicenowsdkgo.WithURL("https://{instance}.service-now.com"),
)
if err != nil {
log.Fatal(err)
}
// Step 3: Define raw URL
fileGetRawURL := "https://{instance}.service-now.com/api/now/attachment/{SysID}/file"
// Step 4: Configure request
fileGetStdConfig := &attachmentapi.AttachmentItemFileRequestBuilderGetRequestConfiguration{
// Optional configurations
}
// Step 5: Build request
fileGetBuilder := attachmentapi.NewAttachmentItemFileRequestBuilder(fileGetRawURL, client.GetRequestAdapter())
fileGetStdResponse, err := fileGetBuilder.Get(context.Background(), fileGetStdConfig)
if err != nil {
log.Fatal(err)
}
}