Legacy Dev Forum Posts

 View Only

Sign Up

POST API call in PowerShell does not return data

  • 1.  POST API call in PowerShell does not return data

    Posted 06-05-2025 18:23

    TodorGeorgievGeorg | 2022-10-06 07:24:54 UTC | #1

    Hi All,

    I would like to use PowerShell in order to automate a task so we can receive a report for the number of abandoned calls for the last 8 hours.

    This is the script I use:

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Authorization", "Bearer MY BEARER TOKEN") $headers.Add("Content-Type", "application/json") $interval = Get-Date (Get-Date).ToUniversalTime().AddHours(-8) -UFormat '+%Y-%m-%dT%H:%M:%S.000Z' $interval2 = Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z'

    $body = "{ n "interval": "$interval/$interval2", n "groupBy": [], n "filter": { n "type": "and", n "predicates": [ n { n "type": "dimension", n "dimension": "queueId", n "operator": "matches", n "value": "OUR QUEUE ID" n }, n { n "type": "dimension", n "dimension": "mediaType", n "operator": "matches", n "value": "voice" n } n ] n }, n "views": [], n "metrics": [ n "tAbandon" n ] n}"

    $response = Invoke-RestMethod 'https://api.mypurecloud.de/api/v2/analytics/conversations/aggregates/query' -Method 'POST' -Headers $headers -Body $body $response | ConvertTo-Json

    The request is accepted with 200OK but the response is only "{}". I suspect that the issue is caused by the date format I use although it's matching the ISO 8601 standard you use. Could you please advise on how to modify the query so I can get it to work?

    Thanks!


    John_Carnell | 2022-10-06 14:46:17 UTC | #2

    Hi Todor,

    Have you tried to reproduce the call in our API explorer for this API. The API explorer should allow you to build the body of the call using the fields based on the swagger doc. You can then compare the body generated by the API explorer against what you are trying to build and see if there is a difference.

    Thanks, John Carnell Manager, Developer Engagement


    TodorGeorgievGeorg | 2022-10-10 10:27:21 UTC | #3

    Hi John,

    Thank you for looking into this topic.

    I used the api query builder from the dev tools to write the query, then I moved to postman to add my bearer token and export the json to powershell format. When I use the time intevals set from the api builder everything works as expected - both in postman and in the powershell ISE. However, when I generate a new time frame like this:

    $interval = Get-Date (Get-Date).ToUniversalTime().AddHours(-8) -UFormat '+%Y-%m-%dT%H:%M:%S.000Z' $interval2 = Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z'

    $body = "{ n "interval": "$interval/$interval2`",

    I get blank response. The POST is accepted - I just don't receive any data so I believe that the API does not like the formatting although it maches the required ISO standard.


    system | 2022-11-10 10:27:41 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: 16605