Skip to main content
Version: v2.0

Create attachment file

Overview​

Upload file of any supported content type. Requires you to provide the table sys id, table name, and file name via the request query parameters.

Path parameters​

N/A

Optional query parameters​

NameTypePossible valuesDescription
EncryptionContext*stringN/Asys_id of an encryption context record.

Required query parameters​

NameTypePossible valuesDescription
FileName*stringN/AName to provided file.
TableName*stringN/AName of the designated table which contains the record to attach the file to.
TableSysID*stringN/ASpecifies the sys_id of the record in the designated table to attach the file to.

Examples​

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

// Build media type
dataContentType := "text/plain"
data := []byte("this is example data")
media := attachmentapi.NewMedia(dataContentType, data)

createFileTableSysId := "{SysID}"
createFileTableName := "{TableName}"
createFileFileName := "example.txt"

createFileConfig := &attachmentapi.AttachmentFileRequestBuilderPostRequestConfiguration{
QueryParameters: &attachmentapi.AttachmentFileRequestBuilderPostQueryParameters{
TableSysID: &createFileTableSysId, // required
TableName: &createFileTableName, // required
FileName: &createFileFileName, // required
},
// Optional configurations
}

createFileResponse, err := client.Now().Attachment().File().Post(context.Background(), media, createFileConfig)
if err != nil {
log.Fatal(err)
}
}
Was this page helpful?