15

I've crawled though as much documentation as I can find but I'm unable to find a swagger file for https://graph.microsoft.io/

There appear to be a couple of variations on this API and I've seen references to the Office 365 Graph API and Azure Graph API but I believe that Microsoft Graph is that latest unified version and provides the features I'm after.

I'd like to use the with Microsoft Flow and I was surprised that it wasn't integrated as an API out of the box. To register a Custom API with Flow however you need to provide a swagger file, hence the question.

Paul Clarke
  • 171
  • 1
  • 6

2 Answers2

5

I found something to convert between OData XML metadata to swagger. https://github.com/akorchev/odata2openapi

The msgraph metadata for beta is at https://graph.microsoft.com/beta/$metadata.

For TypeScript, you would do something like this:

import { odata2openapi } from 'odata2openapi';

odata2openapi('https://graph.microsoft.com/beta/$metadata')
.then(swagger => console.log(JSON.stringify(swagger, null, 2)))
.catch(error => console.error(error))

UPDATE: I noticed there was an error when trying it. I believe because the code did not handle when EntityType node did not have any Properties nodes. I put in a pull request to fix that. https://github.com/akorchev/odata2openapi/pull/7

Chau Nguyen
  • 894
  • 8
  • 13
3

There is an Open API (an evolution of Swagger) preview service description available for Microsoft Graph at this GitHub repo (/beta and /v1):

https://github.com/microsoftgraph/microsoft-graph-openapi

Currently it does not cover everything in Graph API. In the future the Open API descriptions will be published as part of the Graph API in a similar way as the $metadata endpoint is today.

You can use the Open API Tools to create a C# client (or any other supported language) for it. Here is an example for generating the v1.0 and beta clients using their docker image:

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-openapi/master/v1.0.json -g csharp -o /local/out/graphv1
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-openapi/master/beta.json -g csharp -o /local/out/graphbeta
Jeff Widman
  • 22,014
  • 12
  • 72
  • 88
Bernd
  • 539
  • 3
  • 10
  • It seems to have moved here: https://github.com/microsoftgraph/msgraph-metadata/tree/master/openapi – ADJenks Feb 16 '23 at 22:54