Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

PowerShell REST API Get User Info -Body??

SkyPittman
Contributor II

The RESTful API Reference Guide 6.5 has the following info but there are issues.  1. if following the "note" there is not an example of what the body is supposed to look like. 2. if you choose to ignore the note you cannot execute the call by even spelling out the userid in the uri you get an error 400.

It frustrates me to no end that these guides are horribly written.  The cdata examples section doesn't give you any help to build the body when going to it.

 

Does anyone know how this body or the uri is supposed to be setup for this to work?

 

Get user by ID

The Get user by ID resource retrieves a user by the specified ID.

Note: The data that this API returns is more secure when you use an Open Data Protocol (OData)

query in the request body (for more information, see Open Data Protocol (Odata). In this case you

must use the HTTP verb POST instead of GET. Also, using POST is valid only if you include the XHttp-

Method-Override:GET statement in the request header. Otherwise, POST returns an error.

Request

POST http://rsaarcher/platformapi/core/system/user/*userid*

POST http://rsaarcher/platformapi/core/system/user/1470

Request Header

Accept: application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Authorization: Archer session-id="*SessionToken"

Content-Type: application/json

X-Http-Method-Override: GET

Request Body

none

 

 

My goal is in my script is to have the script prompt with input at the beginning of the launch like below.  Then have the input securely transmitted and retrieve that specific users contact info and then export the data to a file.

$archeruser = Read-Host -Prompt 'Input username to query'

#login data and call removed for example#

$api_url = $base_url + "/platformapi/core/system/user/?????"

$body = ??????????

$results_user = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headersGET -Body $body -ContentType "application/json" -WebSession $sess

$results_user.RequestedObject | Out-File -Encoding utf8 -FilePath C:\ArcherUserInfo.txt

1 ACCEPTED SOLUTION

Accepted Solutions

JeffLetterman
Archer Employee
Archer Employee

The Get User by Id call is expecting an integer value, but it sounds like you are wanting to get user info based on the UserName.  To do this, use OData with the Get all users call...see Metadata User

 

Here is a PowerShell example passing OData value in the URL to filter where UserName equals $archeruser:

$api_url = $base_url + "/api/core/system/user?`$filter=UserName eq '$archeruser'"
$results_user = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headersGET -Body $body -ContentType "application/json"
$results_user.RequestedObject‍‍‍‍‍‍‍‍‍

 

To pass the OData value in the body, try this:

$api_url = $base_url + "/api/core/system/user"
$body = @{
Value = "?`$filter=UserName eq '$archeruser'"
} | ConvertTo-Json
$results_user = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headersGET -Body $body -ContentType "application/json"
$results_user.RequestedObject‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

3 REPLIES 3

JeffLetterman
Archer Employee
Archer Employee

The Get User by Id call is expecting an integer value, but it sounds like you are wanting to get user info based on the UserName.  To do this, use OData with the Get all users call...see Metadata User

 

Here is a PowerShell example passing OData value in the URL to filter where UserName equals $archeruser:

$api_url = $base_url + "/api/core/system/user?`$filter=UserName eq '$archeruser'"
$results_user = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headersGET -Body $body -ContentType "application/json"
$results_user.RequestedObject‍‍‍‍‍‍‍‍‍

 

To pass the OData value in the body, try this:

$api_url = $base_url + "/api/core/system/user"
$body = @{
Value = "?`$filter=UserName eq '$archeruser'"
} | ConvertTo-Json
$results_user = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headersGET -Body $body -ContentType "application/json"
$results_user.RequestedObject‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

SkyPittman
Contributor II

That worked thank you.

PatCD
Contributor II

Thanks - this was exactly what I needed to make my day.  :-)