Sending Attachments from ServiceNow to Azure DevOps through REST API's

Prashanth Ranga
Tera Contributor

Hi All , 

 

Can you please let me know how we can send attachments(when created and or updated) from ServiceNow to Azure DevOps through API . 

 

Any code which can be written in business rule/script include would help   

 

Thanks In Advance 

Prashanth 

 

4 REPLIES 4

Mehta
Kilo Sage
Kilo Sage

Create a business rule on attachment table and can have condition depending on your use case. 

You can use below script as sample to send attachment. Make sure to change your request header as per your Azure API shared with you. 

 

var incidentGR = new GlideRecord('incident');
    incidentGR.addQuery('sys_id', current.table_sys_id);
    incidentGR.query();
    if (incidentGR.next()) {
        if (incidentGR.u_case_id != '') {
            try {
                var r = new sn_ws.RESTMessageV2('SOCIntegrationTask', 'Upload File');
                r.setRequestHeader('Appian-Document-Name', current.file_name);
                r.setQueryParameter('taskid', incidentGR.u_task_id);
                r.setQueryParameter('application', incidentGR.u_application);
                r.setRequestBodyFromAttachment(current.sys_id);
                var response = r.execute();
                var request = r.getRequestHeader();
                var responseBody = response.getBody();
                var httpStatus = response.getStatusCode();
            } catch (ex) {
                var message = ex.message;
            }
        }
    }

 

Please Mark it as correct or helpful, if it resolves your query.

@Prashanth Ranga 

 

were you able to resolve this ?

Prateek kumar
Mega Sage

Please check out attachment API

https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Mathieu Lepoutr
Mega Guru

Hi Prashanth

To send attachments through the API, you can utilize the ADO REST API's Create Attachment or Update Attachment endpoints. Please prepare the request to ADO API: Build the HTTP request to the ADO API endpoint, including the necessary headers and authentication information. Ensure that you include the appropriate API version and project-specific details and convert the attachment to base64. Include the attachment data in the API request and then finally send the API request.

 

While developing this integration, you may encounter complexities or specific requirements that can be addressed by using an integration platform like Exalate. I have been using it for a year and it works really well for use-cases like this.