Question

How to add an existing asset to an existing ticket with the API?

  • 25 April 2023
  • 0 replies
  • 34 views

Badge

Pretty much what the title says. I’ve managed to do some pretty cool stuff with the API and PowerShell scripts running on a schedule. Unfortunately, this isn’t something I’ve been able to do.

If someone could provide an example of a JSON File containing the body on how an asset is added, that would be great. So far, this is what I have:

 

$APIKey = 'MyApiKey'
$EncodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(('{0}:{1}' -f $APIKey, $null)))
$Header = @{}
$Header.Add('Authorization', ('Basic {0}' -f $EncodedCredentials))

$parameters = @{



assets = @{
display_id = "8232"
}
}

$Parameters = ConvertTo-Json $parameters

invoke-RestMethod -URI 'https://MyDomain.freshservice.com/api/v2/tickets/147710' -Headers $Header -ContentType "application/json" -Method PUT -Body $Parameters

 

For clarity, that would make the JSON contents:
 

{
"assets": {
"display_id": "8232"
}
}

I probably am missing something but just wanted to see if anyone has any ideas?


0 replies

Join the Community or User Group to Participate in this Discussion

Reply