IT Process Automation

 View Only
  • 1.  Add attachment via Rest API

    Posted Jun 05, 2019 02:57 PM

    I have been successfully creating tickets in CA Service Desk using Powershell for a couple years now, but I have been tasked with figuring out how to add an attachment to the ticket.  They way I create tickets currently is, once I have the $accesskey:

            $URIString = "http://$servername:8050/caisd-rest/cr"

            $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
            $headers.Add("X-AccessKey", $accesskey)
            $headers.Add("Accept", "application/xml")
            $headers.Add("Content-Type", "application/xml; charset=UTF-8")
            $headers.Add("X-Obj-Attrs" , "ref_num")

            $body = "<cr><group COMMON_NAME=`"Security Admin`"/><summary>`"Test Ticket - Please Ignore`"</summary><requested_by COMMON_NAME=`"AutomationReview, UserAccess`"/><customer COMMON_NAME=`"AutomationReview, UserAccess`"/><description>`"Test Ticket - Please Ignore`"</description></cr>"

            $b = Invoke-RestMethod -Method POST -Uri $UriString -Headers $headers -body $body
           

    This works great, but I can't figure out how to add an attachment.  I tried adding "<attachment>`"C:\temp\empID.txt`"</attachment>" to the middle of the body, and while that didn't throw any errors, it didn't seem to do anything.

    Can anyone point me in the right direction?  I've looked at the Java examples, but don't really understand what they're doing there, and how to translate it to Powershell.



  • 2.  RE: Add attachment via Rest API

    Posted Jun 06, 2019 08:21 AM
    Hi,
    maybe the following thread might help.
    https://community.broadcom.com/HigherLogic/Security/SAML/localSAMLLoginService.aspx?binding=HttpPost&ReturnUrl=https%3a%2f%2fcommunity.broadcom.com%2fenterprisesoftware%2fcommunities%2fcommunity-home%2fdigestviewer%2fviewthread%3fMessageKey%3d9842bdca-0e7c-4a3f-9b69-4dae40262e71%26CommunityKey%3de2cd3188-49bc-4f38-88f1-74260f56fa66%26tab%3ddigestviewer
    Broadcom remove preview
    View this on Broadcom >


    In general you need to send a multipart http request.
    How this can be done in powershell, I dont know.
    Regards
    ...........Michael

    ------------------------------
    Principal Services Consultant
    HCL Enterprise Studio
    ------------------------------