API - Get Incidents by Requester (Powershell)

Document created by Sam Buccieri-Gillett on Nov 30, 2017Last modified by Sam Buccieri-Gillett on Dec 4, 2017
Version 3Show Document
  • View in full screen mode

Below examples are for Powershell, but you could adapt easily for other options.

You can't first get a user by email and use their id value returned by the api to make a request for Incidents they are the requester of, e.g.

$user = Invoke-RestMethod -Uri "$apiAddr/users.json?email=someone@example.com" -Method Get -Credential $CredsTrial -ContentType "application/json"

$Incidents = Invoke-RestMethod -Uri "$apiAddr/incidents.json?requested_by=$($user.id)" -Method Get -Credential $CredsTrial -ContentType "application/json"

This doesn't work as the 'requested_by' URL parameter when querying Incidents expects the user's 'requester ID' which doesn't exist in the user record; it exists in the (undocumented) 'requester' record for that user. The following is therefore the valid solution:

$user = Invoke-RestMethod -Uri "$apiAddr/users.json?email=someone@example.com" -Method Get -Credential $CredsTrial -ContentType "application/json"
 
$requester = Invoke-RestMethod -Uri "$apiAddr/requesters.json?user_id=$($user.id)" -Method Get -Credential $CredsTrial -ContentType "application/json"
 
$Incidents = Invoke-RestMethod -Uri "$apiAddr/incidents.json?requested_by=$($requester.id)" -Method Get -Credential $CredsTrial -ContentType "application/json"

 

Attachments

    Outcomes