Skip to content

Get attachment file

Overview

Retrieves an attachment's file data by sys id.

Path parameters

Name Description
baseurl The absolute base URI for the request (this is the same for all requests) including: the schema, the domain, and a path fragment.
sysId The sys id of the attachment.

Optional query parameters

N/A

Required query parameters

N/A

Examples

package main


import (
    "context"
    "fmt"
    "log"
    "os"

    servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go"
    attachmentapi "github.com/michaeldcanady/servicenow-sdk-go/attachment-api"
    "github.com/michaeldcanady/servicenow-sdk-go/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)
    }



    file_get_config := &attachmentapi.AttachmentItemFileRequestBuilderGetRequestConfiguration{
        // Optional configurations
    }

    file_get_response, err := client.Now2().Attachment2().ByID("{SysID}").File().Get(context.Background(), file_get_config)
    if err != nil {
        log.Fatal(err)
    }

}
package main


import (
    "context"
    "fmt"
    "log"
    "os"

    servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go"
    attachmentapi "github.com/michaeldcanady/servicenow-sdk-go/attachment-api"
    "github.com/michaeldcanady/servicenow-sdk-go/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
    file_get_rawURL := "https://https://{instance}.service-now.com/api/now/attachment/{SysID}/file"

    // Step 4: Configure request
    file_get_std_config := &attachmentapi.AttachmentItemFileRequestBuilderGetRequestConfiguration{
        // Optional configurations
    }

    // Step 5: Build request
    file_get_builder := attachmentapi.NewAttachmentItemFileRequestBuilder(file_get_rawURL, client.RequestAdapter)

    file_get_std_response, err := file_get_builder.Get(context.Background(), file_get_std_config)
    if err != nil {
        log.Fatal(err)
    }

}