Home > database >  MS Graph API - getPstnCalls from C#
MS Graph API - getPstnCalls from C#

Time:01-24

I am having trouble figuring out how to call getPstnCalls from MS Graph in C#. I am currently using the latest version of Graph, Microsoft Graph 4.51.0. According to the enter image description here

CodePudding user response:

SDK 4.51 doesn't have support for getPstnCalls but there is a model PstnCallLogRow for pstnCallLogRow resource type.

You can at least try to create a http request and deserialize the response object.

var requestUrl = client
     .Communications
     .CallRecords
     .AppendSegmentToRequestUrl("getPstnCalls(fromDateTime=2023-01-18T06:00:00Z,toDateTime=2023-01-24T07:00:00Z)");

// create GET request message
var hrm = new HttpRequestMessage(HttpMethod.Get, requestUrl);

// authenticate request message
await client.AuthenticationProvider.AuthenticateRequestAsync(hrm);

// send the request
var response = await client.HttpProvider.SendAsync(hrm);
if (response.IsSuccessStatusCode)
{
    // read response json string - it should be a collection of pstnCallLogRow
    var responseString = await response.Content.ReadAsStringAsync();

    // deserialize to a collection of PstnCallLogRow
    var logRows = client.HttpProvider.Serializer.DeserializeObject<List<PstnCallLogRow>>(responseString);
}
else
{
    throw new ServiceException(
                    new Error
                    {
                        Code = response.StatusCode.ToString(),
                        Message = await response.Content.ReadAsStringAsync()
                    });
}
  • Related