Unauthorized request for call history API(Unable to get call history)

Hi,

I am trying to get the call history but getting “Unauthorized Request.”.

Below is curl Request.

curl --location ‘https://media.api.mitel.io/2017-09-01/calls/records’
–header ‘x-mitel-app: app=app=red-spot-interactive-api/1.0.0;platform=windows/10;session=75aece25-1a51-408c-a1ab-209c2a8e8407;’
–header ‘Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0ODc0NTA4MjcvMjkwMTNmOWYtZTI2NS00NWVmLTg3YTktZDE5M2YwNmU5YjMzLzY3NmM0OTdmLTEwNDktNGUxNS05M2UwLTExNDYzMDA3YTFkNSIsInNjb3BlIjoicm9sZTpQQVJUTkVSX0FETUlOLHBvbGljeUlkOmU4MWQxN2M3LTE4M2UtNGM0ZS1hZTBiLTA2NDhhNGY0NzA3Mix2ZXI6Myx0eXBlOnVzZXIiLCJpc3MiOiJodHRwczovL2F1dGhlbnRpY2F0aW9uLnVzLWVhc3QtMS51cy5hcGkubWl0ZWwuaW8vY2xvdWRsaW5rIiwiaWF0IjoxNzE0Mzk2NTcxLCJleHAiOjE3MTQ0MDA0NTd9.sKmcHDs_YPwY77hEJGcT0qiw3075CfoHUgoy5ZVgN0g’

From where can get the values of “x-mitel-app” , “applicationId,” and “session-id”?
I have checked the document and tried to use the below values but got same response.

“x-mitel-app” => “app=red-spot-interactive-api/1.0.0;platform=windows/10;session=75aece25-1a51-408c-a1ab-209c2a8e8407;”

The reason why its not working as it requires a filter parameter to which user you are trying to receive for example:

curl -X GET “https://media.api.mitel.io/2017-09-01/calls/records?%24filter=contains(principal%2C%20‘9c82d10c-aa4f-4b19-a678-81e04e44f98a’)” -H “accept: application/json” -H "authorization: Bearer {{token}}

Thanks Justin,

What value should the principal parameter have? I tried to use sessionId but I still get the “Unauthorized request.” error. If this is the user id, where should get it?

GET /2017-09-01/calls/records?$filter=contains(principal%2C%20%2775aece25-1a51-408c-a1ab-209c2a8e8407%27)&$skip=0&$top=100 HTTP/1.1
x-mitel-app: app=redspot-web/1.0.0;platform=windows/10;session=75aece25-1a51-408c-a1ab-209c2a8e8407
Authorization: Bearer TOKEN_VALUE
User-Agent: PostmanRuntime/7.39.0
Accept: /
Cache-Control: no-cache
Postman-Token: b74ec12d-9e3c-48a6-8e41-1b27beffc8b4
Host: media.api.mitel.io
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

HTTP/1.1 401 Unauthorized
Content-Type: application/json
Content-Length: 35
Connection: keep-alive
Date: Thu, 23 May 2024 09:35:34 GMT
x-amzn-RequestId: 0ffcc13a-a138-4ddc-91c7-9e6c8919d5ab
Access-Control-Allow-Origin: *
x-mitel-correlation-id: 777b8c20-e471-484b-b961-8f85f41227d4
x-amz-apigw-id: YN8cAHzlvHcEGAg=
Cache-Control: no-cache, no-store, must-revalidate
Expires: 0
X-Amzn-Trace-Id: Root=1-664f0de6-5b4654b126d215687f11a43b;Parent=44b7a0b827ea52af;Sampled=0;lineage=a8f4eec1:0|be6af366:0
Pragma: no-cache
X-Cache: Error from cloudfront
Via: 1.1 5af319db9b3c24acf5b1e1c9d198ae7e.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: MIA3-P8
X-Amz-Cf-Id: _fhfRlqw0qkRUyfF0VoIMDyM5D5ZNIzCYC_707rqMs-PdbxsKZj12A==

{“message”:“Unauthorized request.”}

Is it possible to get calls for all users inside the Mitel account? Something like $filter=contains(account,ACCOUNT_ID) here. Also, how to provide the date range?

We want to get all calls made by all users in the account within a specific date range - what OData request should we use to achieve that?

Regards,
Vlad

Hi Vlad,

Hopefully I can answer you questions below:

What value should the principal parameter have?

The principal parameter would be the userId obtained through a call to the auth micro, that would look something like this:

GET: https://authentication.api.mitel.io/2017-09-01/token

with the Authorization header being the token that you created.

The response would look like this:

{
“role”: “ACCOUNT_ADMIN”,
“iss”: “https://authentication.us-east-1.us.api.mitel.io/ad”,
“principalId”: “3be104db-968d-4eaf-946c-a77545953841”,
“integrationLatency”: 0,
“type”: “user”,
“userId”: “3be104db-968d-4eaf-946c-a77545953841”,

}

the userId would be the value to use in the call history request.

Is it possible to get calls for all users inside the Mitel account?

Unfortunately you are not able to receive call history for all users of the platform. You can only receive call history for calls associated with the Cloudlink token that is being used to make the request.

how to provide the date range?

Unfortunately there is no date range option for this route.

Thanks

Thanks Kevin,

Can I get calls for another User in that request? E.g. if I pass another UserId in the payload?

Also, you said that’s not possible to provide the data range - does it mean that your API will always provide all historic calls every time? Is there a way to limit the results somehow?

HI Vlad,

Please find the answers to your questions below:

Can I get calls for another User in that request? E.g. if I pass another UserId in the payload?

In order to get the historical calls for another user, you would need to obtain a Cloudlink token for the user in question and pass it in the Authorization token with your request. For the most part, the APIs only allow queries for information associated with the CL token that was passed in the Authorization header request.

Also, you said that’s not possible to provide the data range - does it mean that your API will always provide all historic calls every time? Is there a way to limit the results somehow?

The APIs do support $Top and $Skip query params that would allow you to limit the data that comes back from the request.

ex: GET:?$top=10&$skip=0

Thanks,

Kevin

Thanks Kevin - we managed to make it work.

Question - how we can associate a real phone number for the User to debug the process, and get real call logs?

More relevant question - in our CRM we want to get call history for all users inside an account. We created the Client which acts as an admin which is described here Mitel APIs - Admin

And we would like to use this single client to access all Users call history. We don’t want to keep usernames and password for all users inside our system. We were planning to use that single account access instead. Is this possible to achieve that? The Client has admin access - it is supposed that it should have access to all users data. But when we try its access token to get call history for another user we get 401 - why is that?

How we can implement the logic above without using Users credentials? Will you able to turn on some sort of super admin access for our Client user?

If not - how would you recommend to proceed with the above?

Thanks,
Vlad

Hi Vlad,

Question - how we can associate a real phone number for the User to debug the process, and get real call logs?

This would really depend on what kind of setup you have currently.

Do you have a telephone switch (MiVB) at your disposal?

And we would like to use this single client to access all Users call history.

There is going to be an update to the Media micro that will be available in a couple of weeks that will give you the ability to get user call history for multiple users with an admin account token.

Hopefully this will provide the funtionality that you need for your app.

Thanks

Thanks Kevin,

So, once your team make changes to API within the next two weeks we will be able to get call logs for all users within one account, right? Considering that we have created the ADMIN access client user. If so, that’s exactly what we need!

As to out setup - we have recently created an account, and we don’t have a switch. Ideally, we want to register the virtual phone number and use the kind of web phone / soft phone.

We are building the connection and want to test it before we onboard the clients to it. We need the test phone number which we will be able to use for calls and sms.

NOTE - could you please ask someone to take a look at the case Sending SMS / MMS Messages - it’s been almost 20 days I’ve created one, and I have never received a response :frowning:

Hi Vlad,

As to out setup - we have recently created an account, and we don’t have a switch. Ideally, we want to register the virtual phone number and use the kind of web phone / soft phone.

Unfortunately in order for this to work, you would need a supported Mitel telephony switch and a Cloudlink gateway. Call history is generated from CTI/ CSTA events provided by the telephone switch.

Thanks,