This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Service Desk API - add attachment to new incident?

I am making Service Desk REST API call that creates an incident. It works fine, but I need to add also files/attachments to the new incident.
How to add an attachment to new incident created by Service Desk createIncident API?
Service Desk createIncident API does not return Incident id and Service Desk attachments API requires attachment id?

Parents
  • Hi amhcd, pulling ICJN's answer from this simlar forum post, the JSON format and for adding an attachment to an Incident or to a Comment with Powershell 7 are as follows:

    Attach to an Incident:

    $file = @{
        "file[attachable_type]" = "Incident"
        "file[attachable_id]" = "123456"
        "file[attachment]" = (get-item -path "C:\temp\Test.txt")
    }
    
    $uri = "https://api.samanage.com/attachments.json"
    
    Invoke-RestMethod -Uri $uri -form $file -ContentType 'multipart/form-data' -ResponseHeadersVariable ResponseHeader -Method Post -WebSession $session

    Attach to a comment:

    $file = @{
        "file[attachable_type]" = "Comment"
        "file[attachable_id]" = "123456"
        "file[attachment]" = (get-item -path "C:\temp\Test.txt")
    }
    
    $uri = "https://api.samanage.com/attachments.json"
    
    Invoke-RestMethod -Uri $uri -form $file -ContentType 'multipart/form-data' -ResponseHeadersVariable ResponseHeader -Method Post -WebSession $session

    The "file[attachable_id]" = "123456" is where you would put the incident or comment ID.

    When you create the Incident using the API, the response body should include the ID as well as most of the other fields for the newly created Incident.

    Can you let us know what language or tool you're using the make the API call, and include a snippet of the response body you're receiving?

  • Thanks for this very useful information. I have issue now that I do not see incident id in the output of POST  https://api.samanage.com/incidents API when I'm creating new incident.

    The create incident API has a big html output but there is no id of just created incident. Do you have any information about how to get incident id of just created incident ?

Reply Children