David_Key | 2019-02-14 22:06:40 UTC | #1
I am trying to pull user ID from powershell but i am getting this error.
Invoke-RestMethod : {"status":400,"code":"bad.request","message":"The request could not be understood by the server due to malformed syntax.","contextId":"bba272a9-c2dd-4d17-9b30-71af6f625e8c"
$searchdata = @{ query = @{ fields = @("email") value = $USEREMAIL type = "CONTAINS" } } $searchJSON = $searchdata | ConvertTo-Json
The results look fine to me match the dev query that does work. echo of body { "query": { "type": "CONTAINS", "value": "blah@gmail.com", "fields": [ "email" ] } }
tim.smith | 2019-02-15 14:43:59 UTC | #2
The back-end error is "Can not deserialize instance of java.util.ArrayList out of START_OBJECT token". This means the root element of the request should be an array, not an object. You'll need to put the body you're using inside of an array and send it.
The documentation appears to be incorrect here as it's showing that you should be sending a single object. I've filed SRCH-1945 to correct the documentation.
David_Key | 2019-02-15 17:00:32 UTC | #3
Looking at it enough it eventually clicked. Formatting if any ever needs help with it.
#
Search call powershell
$Searchurl = "https://api.mypurecloud.com/api/v2/users/search" $searchdata = @{ query = @( @{ fields = @('email') value = $USEREMAIL type = "CONTAINS"})}
$searchJSON = $searchdata | ConvertTo-Json -Depth 5
$Result = Invoke-RestMethod -Uri $Searchurl -Headers @{"Authorization" = "Bearer $token"} -Method Post -Body $searchJSON -ContentType 'application/json'
$userid = $Result.results.id
system | 2019-03-18 17:00:33 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 4586