Skip to content

Upload attachment

Overview

Uploads a file to a record in a specified table.

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.

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



    // body := // TODO: how to make multipart body?
    var body abstractions.MultipartBody

    upload_config := &attachmentapi.AttachmentUploadRequestBuilderPostRequestConfiguration{
        // Optional configurations
    }

    upload_response, err := client.Now2().Attachment2().Upload().Post(context.Background(), body, upload_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
    upload_rawURL := "https://https://{instance}.service-now.com/api/now/attachment/upload"

    // Step 4: Build multipart body
    var upload_std_body abstractions.MultipartBody

    // Step 5: Configure request
    upload_std_config := &attachmentapi.AttachmentUploadRequestBuilderPostRequestConfiguration{
        // Optional configurations
    }

    // Step 6: Build request
    upload_builder := attachmentapi.NewAttachmentUploadRequestBuilder(upload_rawURL, client.RequestAdapter)

    upload_std_response, err := upload_builder.Post(context.Background(), upload_std_body, upload_std_config)
    if err != nil {
        log.Fatal(err)
    }

}