---
sourceDocument: Brazil IT Service Management
sourceDocumentLink: https://www.servicenow.com/docs/r/it-service-management

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil IT Service Management

ft:clusterId :

    - itsm

bundleId :

    - itsm

workflow :

    - Technology


---

# Add attachments to change requests using attachment API

# Add attachments to change requests using attachment API {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Add attachments to change requests using attachment API

This guide explains how ServiceNow customers can add test report XML files as attachments to change requests by using the Attachment API.
This integration is particularly useful for customers leveraging DevOps pipelines such as Azure DevOps, GitHub, and Jenkins.
It enables automated uploading of test artifacts directly to change request records in ServiceNow, improving traceability and auditability of deployment activities.
Show full answer Show less  

## Key Features

* **Attachment API Endpoint:** Use the POST API at `/now/attachment/file` specifying `tablename=changerequest`, the change request's `sysid`, and the attachment file name.
* **Azure DevOps Integration:** Requires an active user with `Web service access only` enabled and `snchangewrite` role assigned. The system property `sndevops.enableadogenericconnection` must be enabled. Sample YAML pipeline snippets demonstrate how to invoke the attachment upload via REST API calls.
* **GitHub and Jenkins Support:** Provides example pipeline scripts for uploading attachments within GitHub Actions and Jenkins pipelines, illustrating how to authenticate and post XML files to change requests.
* **Authentication:** Uses basic authentication with a user having the `snchangewrite` role to ensure proper permissions for writing attachments to change records.

## Practical Implementation Notes

* The attachment API URL format requires specifying your instance name and the target change request's `sysid`.
* When configuring DevOps pipelines, use the provided sample pipeline stages to retrieve the change request ID and post attachments via REST calls.
* In Jenkins, Groovy scripts demonstrate how to perform API calls, handle responses, and post XML attachments programmatically.

## Limitations

* The size of the XML file being attached should be acceptable for the orchestration tool to handle.
* Specifically for Azure DevOps, the user must have the `snchangewrite` role to authenticate and upload attachments to the change record.  
Add test report xmls as attachments to DevOps change requests using the attachment API.
For more information about the API, see [Attachment - POST /now/attachment/file](https://www.servicenow.com/docs/access?context=c_AttachmentAPI&version=brazil&pubname=brazil-api-reference&section=attachment-POST-file&ft:locale=en-US).

The attachment API URL is:  
`https://<your_instance>.service-now.com/api/now/attachment/file?table_name=change_request&table_sys_id=$(getServerChange.sys_id)&file_name=<attached_filename.xml>`, where

* table_name = 'change_request'
* table_sys_id = \<chg record sys_id\>
* file_name = Any name for the attachment
{#attachment-api-chg__ul_eqs_jpn_lbc}

## Azure DevOps {#attachment-api-chg__section_q33_xyk_kbc}

Prerequisites  
* Create an active user with the option Web service access only selected. For information on how to create a user, see [Create a user](https://www.servicenow.com/docs/access?context=t_CreateAUser&version=brazil&pubname=brazil-platform-administration&ft:locale=en-US).
* Assign the role sn_change_write to the user. For information on how to assign the role, see [Assign a role to a user](https://www.servicenow.com/docs/access?context=t_AssignARoleToAUser&version=brazil&pubname=brazil-platform-administration&ft:locale=en-US).

* The system property sn_devops.enable_ado_generic_connection must be enabled.
* While configuring your Azure DevOps project, to upload to chg. table, the generic connection used should have a user having the role sn_change_write.
{#attachment-api-chg__ul_hnf_srn_lbc}

For Azure DevOps pipelines, use the format given here to add attachments to change requests.  
Sample pipeline:

    stage: PostDeploy
        jobs:
          - job: 'pd1'
            pool: server
            steps:
               - task: ServiceNow-DevOps-Server-Get-Change@1
                 inputs:
                   connectedServiceName: 'v01-Software Quality Scans-ServiceNow DevOps Service Connection'
                   projectName: '$(system.teamProject)'
                   pipelineName: '$(build.definitionName)'
                   stageName: 'Deploy'
                   jobName: 'd1'
                   buildNumber: '$(build.buildId)'
                   branchName: '$(Build.SourceBranchName)'
                 name: getServerChange  
               - task: InvokeRESTAPI@1
                 inputs:
                   connectionType: 'connectedServiceName'
                   serviceConnection: 'v01 - new'
                   method: 'POST'
                   body: '<root><name>john2</name><age>34</age></root>'
                   urlSuffix: 'api/now/attachment/file?table_name=change_request&table_sys_id=$(getServerChange.changeSysId)&file_name=test3.xml'
                   waitForCompletion: 'false'

## GitHub {#attachment-api-chg__section_agm_wyk_kbc}

For GitHub pipelines, use the format given here to add attachments to change requests.

Sample pipeline:

Attachment in the Change Request form in Now instance:

## Jenkins {#attachment-api-chg__section_pfd_5yk_kbc}

For Jenkins pipelines, use the format given here to add attachments to change requests.  
Sample pipeline:

    pipeline {
        agent any
        
        stages {
            stage('POST API Call') {
                steps {
                    script {
                        def apiUrl = 'https://<your_instance>.service-now.com/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolId>&testType=Smoke'
                        def requestBody = [
                            name: "Smoke tests",
                            duration: 0.0,
                            passedTests: 1,
                            failedTests: 1,
                            skippedTests: 1,
                            blockedTests: 1,
                            totalTests: 4,
                            startTime: "2023-12-14T23:31:31z",
    	                    finishTime: "2023-12-15T23:31:31z",
                            buildNumber: env.BUILD_NUMBER,
                            stageName: "POST API Call",
                            pipelineName: "TestPipelineKL"
                        ]
                        
                        def auth = "<password>" // devops.integration.user:<password> in base64 encoded.
                        def authHeader = "Basic " + auth
                        
                        def response = httpRequest(
                            contentType: 'APPLICATION_JSON',
                            httpMode: 'POST',
                            requestBody: groovy.json.JsonOutput.toJson(requestBody),
                            url: apiUrl,
                            customHeaders: [[name: 'Authorization', value: authHeader]]
                        )
                        
                        if (response.status == 200 || response.status == 201) {
                            echo "API call successful!"
                            echo "Response: ${response.content}"
                        } else {
                            error "API call failed with status ${response.status}"
                        }
                    }
                }
            }
            stage('UAT deploy') {
                        steps {
                            script {
                                def chg_output = snDevOpsChange()
                                def changeRequestNumber = snDevOpsGetChangeNumber(changeDetails: """{"build_number":"${env.BUILD_NUMBER}", "pipeline_name": "TestPipelineKL", "stage_name": "UAT deploy"}""")
                                echo "${changeRequestNumber}"
                                echo "Output of snDevOpsChange(): ${chg_output}"
                        }
                    }
            }
            stage('Example') {
                steps {
                    script {
                        def API_URL = 'https://<your_instance>.service-now.com/api/sn_devops/devops/orchestration/changeInfo?pipelineName=TestPipelineKL&toolId=<devops_ToolId>&buildNumber=' + env.BUILD_NUMBER + '&stageName=UAT%20deploy'
                        def AUTH = 'Basic <password>'
                        // Call the API
                        def response = sh(script: "curl -X GET -H 'Authorization: ${AUTH}' -H 'Content-Type: application/json' '${API_URL}'", returnStdout: true).trim()
                        echo "Response: ${response}"
                        
                        // Store the JSON response into a variable
                        def slurper = new groovy.json.JsonSlurper()
                        def jsonResponse = slurper.parseText(response)
                        echo "Stored JSON Response: ${jsonResponse}"
                        
                        // Store the specific field value from JSON response into a variable
                        def changeId = jsonResponse.result.sys_id
                        echo "Change ID: ${changeId}"
                        
                        // Call the second API to post attachment
                        def xmlData = '<root><name>john2</name><age>34</age></root>'
                        def AUTH2 = 'Basic <password>='
                        def postResponse = sh(script: "curl -X POST -H 'Authorization: ${AUTH2}' -H 'Content-Type: application/xml' -d '${xmlData}' 'https://<your_instance>.service-now.com/api/now/attachment/file?table_name=change_request&table_sys_id=${changeId}&file_name=test10111.xml'", returnStdout: true).trim()
                    }
                }
            }
        }
    }

## Limitations of the attachment API {#attachment-api-chg__section_k1v_shp_kbc}

* The attachment xml file's text size should be acceptable to the orchestration tool.
* For Azure DevOps, sn_change_write role is needed for authentication of attachment API, to upload the file to the change record.
{#attachment-api-chg__ul_zlf_thp_kbc}

