4
votes

I am trying to get the metadata from Office 365 Management APIs. When I a make a call to the following Url

resource = "https://manage.office.com/api/v1.0/tenant-id/ServiceComms/Messages" 

I get the response and in the content, I have the following information (I have replaced the tenant GUID with name):

{
  "@odata.context": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata#Messages",
  "value": [
    {
      "@odata.type": "#Microsoft.Office365ServiceComms.ExposedContracts.Message",
      "@odata.id": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/Messages('LY177449')",
      "@odata.editLink": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/Messages('LY177449')",
      "[email protected]": "#Collection(String)",
      "AffectedWorkloadDisplayNames": [],
      "[email protected]": "#Collection(String)",
      "AffectedWorkloadNames": [

From the response I assumed that I can retrieve metadata from https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata

But when I make an auth call to that Url I just get an Internal server error msg

string resource =
    "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata";
using(HttpClient httpClient = new HttpClient())
{
    httpClient.Timeout = new TimeSpan(0, 2, 0);
    httpClient.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue("Bearer", _authResult.AccessToken);
    httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
    HttpResponseMessage response = await httpClient.GetAsync(resource);
}

In httpClient, I have 2 headers, the Authorization: bearer token (which works fine) and Accept: application/json

In HttpResponseMessage response, I get a 500 Internal Server Error. There is no other information.

I don't understand what I am doing wrong here. Does anyone know how to get the metadata from Office 365 Service Communications API?

1
You should also take a look at the docs here docs.microsoft.com/en-us/openspecs/odata_standards/ms-odatajson/…Nkosi
I would suggest you inspect the content of the response to see if it provides any additional information. When I test you sample URL I get a null reference exception which was expected since I do not have a tenant id.Nkosi
I followed the official docs, I will update the question with responseStudent

1 Answers

0
votes

I would suggest you inspect the content of the response to see if it provides any additional information.

For example

When the service encounters an error, it reports the error response code to the caller, using standard HTTP error-code syntax. As per OData V4 specification, additional information is included in the body of the failed call as a single JSON object. The following is an example of a full JSON error body:

{ 
    "error":{ 
        "code":"AF5000.  An internal server error occurred.",
        "message": "Retry the request." 
    } 
}

Reference Office 365 Service Communications API reference (Preview): Errors

When I test your sample URL

https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata#CurrentStatus

I get a null reference exception

System.NullReferenceException: Object reference not set to an instance of an object.
   at Autofac.Integration.WebApi.AutofacWebApiFilterProvider.GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.<ReverseIterator>d__75`1.MoveNext()
   at System.Web.Http.Controllers.HttpActionDescriptor.<RemoveDuplicates>d__3.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.<ReverseIterator>d__75`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Web.Http.Controllers.HttpActionDescriptor.InitializeFilterPipeline()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Web.Http.Controllers.HttpActionDescriptor.GetFilterGrouping()
   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Office365ServiceComms.MessageHandlers.RequestResponseLogHandler.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()

which was to be expected since I do not have a tenant id nor auth token.

And since this API is in preview then it could very well be an actual problem/bug on their side. Should consider raising an issue if they have that ability available.

When I test the odata examples at odata.org, calling the odata.context returns the schema from their example as expected.