How to use a REST web services HTTP client to upload a file to a repository without attaching it to a ticket

book

Article ID: 130039

calendar_today

Updated On:

Products

CA Service Management - Asset Portfolio Management CA Service Management - Service Desk Manager

Issue/Introduction



 

How do I use a REST web services HTTP client to upload a file to a repository without attaching it to a ticket?  

Environment

CA Service Desk Manager 17.1

Resolution

This example shows how to use the HTTP client named Postman to upload text and image files to the CA Service Desk manager attachments repository. 

The default attachment repository named "Service Desk" has a default repository id of 1002. 

1. To attach a text file (named test.txt),  use Postman and follow the format below.

POST: http://sdm170:8050/caisd-rest/attmnt?repositoryId=1002&serverName=sdm170&mimeType=Text&description=test.txt 

Params: 
Query Params: 
KEY VALUE 
repositoryId 1002 
serverName sdm170 
mimeType Text 
description: test.txt 

Headers: 
KEY VALUE 
X-AccessKey 237219108 
Content-Type [{"key":"Content-Type","value":"multipart/form-data; BOUNDARY=*****MessageBoundary*****" 

Pre-request Script 
pm.environment.set("CR","\r"); 

Body > raw 
--*****MessageBoundary*****{{CR}} 
Content-Disposition: form-data; name="payload" 
Content-Type: application/xml; CHARACTERSET=UTF-8 
{{CR}} 
<attmnt> 
<repository id="1002"></repository> 
<orig_file_name>test.txt</orig_file_name> 
<attmnt_name>test.txt</attmnt_name> 
<description>Upload using REST</description> 
</attmnt> 
{{CR}} 
--*****MessageBoundary*****{{CR}} 
Content-Disposition: form-data; name="test.txt"; filename="test.txt" 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: binary 
{{CR}} 
testing testing
{{CR}} 
--*****MessageBoundary*****--{{CR}}

2. To attach an image file (named test.gif), use Postman and follow the format below.

Note: The test.gif file must be already encoded in base64. You could use a free online converter like the one on this page: https://www.browserling.com/tools/image-to-base64 

POST: http://sdm170:8050/caisd-rest/attmnt?repositoryId=1002&serverName=sdm170&mimeType=Text&description=test.txt 

Params: 
Query Params: 
KEY VALUE 
repositoryId 1002 
serverName sdm170 
mimeType Text 
description test.txt 

Headers: 
KEY VALUE 
X-AccessKey 237219108 
Content-Type multipart/form-data; BOUNDARY=*****MessageBoundary***** 

Pre-request Script 
pm.environment.set("CR","\r"); 

Body: > raw: 
--*****MessageBoundary*****{{CR}} 
Content-Disposition: form-data; name="payload" 
Content-Type: application/xml; CHARACTERSET=UTF-8 
{{CR}} 
<attmnt> 
<repository id="1002"></repository> 
<orig_file_name>test.gif</orig_file_name> 
<attmnt_name>test.gif</attmnt_name> 
<description>Upload using REST</description> 
</attmnt> 
{{CR}} 
--*****MessageBoundary*****{{CR}} 
Content-Disposition: form-data; name="test.gif"; filename="test.gif" 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: base64 
{{CR}} 
R0lGODlhFgAZAPcAAOutJO+sIOyvMuu3Le60L+WzOumwPOq4MfOmIvCmKfCrIvGvI/aqI/GtLvarLviuJ/OvMvWvNfewIvG9LPW8LfuwI/+yJP62JviyLvu2Lf22K/+3LPq6Lfu+L/G1PfO6OfC6PvK8OPW/O/qwN/23M/i/NP64NP+/M/u9OPu/Pf64Pty0Q9u1SN+2TNu7VN27Wt2vYdi4f+C3ReO4Ree9ROO4SO+9TOG7UeW7UuG9X+a8Wu+1Ueq6VO24UOq5Xfe7Tfq5Q+O+eunFM+jAPevFPuvPP/PDO/DBPfnAMfnCNfvEM/7FMP/HNvrFOf/BPf/LNfrLPf/OOP7MPf3QP9zHStvCZd3Nbd3NduzAQ+3DS+jJTObAU+bHU+LAXuPMXOnIVOfQXvXCQvHHT/TNQvTMSfnCRP3HQP7KQv/OQP/PTPTGVvXJUP/OUfvLX/HTUfrRX+XBZOPBauTEbevHZ+rFaubDcuHEeOrTa+HQfvfJfvjHePrNcu/PhuvJiezPjefVienXje/SjuXWm+XZnerVkvDQh/HWifbQif7Tj/rbiPrdm/rcnPTbovzfpf/unP7iqv3irf/lqfnoo//tov/orP/tqPHntPPptv/jsP/kvP/qsf/pt//stPnvvv/vuv/2s//2uu7kwfnv1P/ywP/wx//1x//xyv/0yv/2yP/3zv/5xf/5zv/8y//9z//y1P/10v/13P/70//71v//0//91//62v/53f/92P/+3v/24//15f726//27v/54f/45P/84P//4f//4v/95P/95v/+5P/+5v/67P/77//86P/96v/97P/+7P7/7/Dz+vf2+/b3/Pf98fT/8vf/9PX/9vL/+vb4//f/+PX/+/b8//T//v/38v73//j+9Pj/9v/58f769f/98f/88/7/8P/+8//89P/89v/+9P7+9vr6+Pj4//r6/Pn6//n/+fr8/vr//Pr+//76+f75/f/5/v/7/P76///8+P78+v7++P7++v78/P78/v7+/P3+/wAAAAAAAAAAACH5BAEAAP8ALAAAAAAWABkAAAj/AN+92zcuGLBx+N5lk8bNHT979vi9w3fvXLl3/PjtY7bsHr9277pJU6dvXj6JFCtm1EcvY8Z2/O7ho0dTX8Z9+Cji41dzZT5zyJSx1BfPpUZ8zHYKFMjP3C9Ll0TtwnfSKL9l4/hl2/pOnzJUeK4ICjVun1V+zMSdY0ctWzt6xkB5oWJl0DKcOzO+q3dOZLRr+uTp+uSmCBhAxeqBy6pXXktr0abR25YLERkhXCb98iasmDaJ2BzrQ8oMHq9MetJMeeNolatTsZSdxEZPnr5zwWiZwpSnh5kmNvYc6hOIka1y+t7lg2dvWSdJhui0KSMliYEePHTksENK9sRz43D9/7nzZcgZJlE6CPDwIUwWOJyE7bR5bFUVLWOkKFnyhEMDCAtQYMQWi9TiEU3esOICEVCgccYZUnAQwQgMaDABDXy8cs5k23zTygtYiICCE06coEACDiCQQRJiFCKLOc6wFM4rQfjwgwomaGBBBQ9gYEIKbNygSC3h8KOPPcq8EgMMOwBBwgYXSBAAAASAoAYcmuDiETTiBDMLIXLgUEAIJSBBwQAHHLEGDnWMQsw977jDzTK4qFJJInO0UMMMMqzAwg1dxOFHKsugI1A16cAzDjG3lOKJJpRE8sgjkDzSyCa/jAPSOuu0s44+8JCjDDLD9GKqL77AQsstysD5TjXtwDrEzzPqfFPON96QU0499ZCTTDLk2MMUSM0sFadG+0CEUzne2JNcNudEe8497FRrLTv3ZIvPPjZJ9E5AADs= 
{{CR}} 
--*****MessageBoundary*****--{{CR}}

<Please see attached file for image>

Additional Information

Postman can be downloaded from here: https://www.getpostman.com/
 

Attachments

1558688444673000130039_sktwi1f5rjvs16flc.png get_app