API v3 Add Attachment To Ticket

API v3 Add Attachment To Ticket

This is the code that I have cobbled together based on various resources, such as the public beta documentation and the API documentation in my tenant.

  1. $ApiKey = "API-KEY-GOES-HERE" # Technician API Key
  2. $SdpUri = "https://servicedesk.contoso.com"
  3. $RequestID = "111111"

  4. $input = @"
  5. {
  6.     "attachment": {
  7.         "filename": "@C:\temp\test.txt",
  8.         "addtoattachment": true,
  9.     }
  10. }
  11. "@

  12. $header = @{TECHNICIAN_KEY=$ApiKey} 
  13. $params = @{input_data=$input;format='json'}
  14. $Uri = $SdpUri + "/api/v3/$RequestID/attachment"
  15. $result = Invoke-RestMethod -Method GET -Uri $Uri -Headers $header -Body $params -ContentType "application/x-www-form-urlencoded" 
  16. $result

Could someone please point me in the right direction as to formatting my JSON input? I have a separate script that I am able to get attachments with but I would like to be able to add an attachment to an existing ticket. Currently I am receiving a status_code 4007 "failed" when attempting to run the above code.

                  New to ADSelfService Plus?