打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Microsoft Graph API and the Power Platform, the Ultimate guide
userphoto

2023.06.20 天津

关注

在使用 Power Automate时,我经常被问到及有关 Graph API 的问题可能很难正确配置。只要有一个字符错误,Power Automate 可能会让您的一些错误消失息,让您花费数天时间进行调试。

什么是 Microsoft Graph API?它是一个 API(应用程序编程接口),可以让您直接从应用程序或流程访问许多 Microsoft 技术。当然,您也可以在 Power Platform 之外部使用 Graph API,但在我的示例中其中,我想重点关注电源平台。

那么,Graph API 是如何工作的呢?

API的工作方式是您调用一个URL,该URL返回您另外可以使用的json数据。您可以在浏览器中对此进行测试,如果您所见,我们正在返回一些信息。(也许不是我们想要的数据,但我们仍然会得到一些回报。

在上面的示例中,您可以看到我们需要整理出一个身份验证令牌。为了测试目的,我们可以使用与上述浏览器具有相同url的Graph Explorer ,现在我们将返回一些数据。

以上e 工作,因为我们已经使用了我的 Microsoft 365 用户登录,因此我已经通过了身份验证。在这篇文章的后续部分,我将了解 API 的身份验证证书部分在从 Power Automate 调用 API 时的实践工作原理

Microsoft Graph API 涵盖的领域

Graph API 有许多端点,https://graph.microsoft.com/v1.0/me端点只是众多可用端点之一。

在 Microsoft 365 系统中,您可以使用图形 API访问以下任何区域

  • 用户
  • 团体
  • 应用
  • 日历
  • 更改通知
  • 遵守
  • 跨设备体验
  • 客户预订
  • 设备和应用程序管理
  • 教育
  • 扩展
  • 文件
  • 身份和访问
  • 邮件
  • 笔记
  • 人与工作场所智能
  • 个人联系方式
  • 报告
  • 搜索
  • 安全
  • 网站和列表
  • 任务和计划
  • 团队合作与沟通
  • 待办事项
  • 工作簿和图表

好的,有很多值得关注的领域。在这一系列的文章中,我将探讨不同的领域以及我们如何利用这些领域。

Power Automate 和 Microsoft Graph API

我们如何使用 Power Automate 的 Graph API?

有几种不同的方法。熟悉这些选项很重要,因为或许可以稍微降低你的成本。

在 Power Automate 中,您可以使用高级 HTTP 操作来调用 Microsoft Graph API,如下所示,对于许多 Graph API,您将需要使用此操作。

但是,对于 Microsoft Graph API 的某些区域,您可以使用非高级许可证中包含的标准操作。

在以下连接器中可以找到这些“免费”HTTP 请求操作:

  • Office 365 展望
  • Office 365 用户
  • Office 365 组
  • Office 365 组邮件
  • 学习管理系统 365

对于上述 5 个连接器,身份验证已经变得很容易,但是当您使用更基本的 HTTP 操作时,您将必须做更多的工作才能使其全部正常工作。

身份验证和 Microsoft Graph API

过去,我会使用两个 HTTP 步骤来首先收集访问令牌,但现在我们只需选择 Active Directory OAuth 并在下面的表单中提供租户、受众、客户端 ID 和密钥的详细信息。

这是怎么回事?

在 Azure 门户中,我们可以创建应用程序注册,然后为其提供权限。应用程序注册将为我们提供秘密(或者您可以使用证书)。

正如我们之前所看到的,Graph API 中有一个应用程序 API,因此我们可以使用 API 本身创建此应用程序,但是我们仍然需要应用程序注册才能使其正常工作。

创建应用程序注册

通过转到Azure 门户中的应用程序注册,可以创建新的注册并可以调整现有的应用程序注册。请小心更改现有的应用程序注册,因为您可能会破坏授予现有应用程序的权限。

当您点击“新注册”时,首先需要做出选择。谁可以使用该应用程序?

您现在可以选择应用程序注册是否只能在您的租户内使用,或者其他帐户是否也可以访问。

创建应用程序后,我们现在就有了可用的应用程序 ID、租户 ID。

在应用程序注册中创建一个秘密

下一步是创建秘密。您所要做的就是提供说明和到期日期。

然后你就会得到这个秘密。请注意,您将获得 Secret Value这是您想要保留的东西,因为您只会得到一次。如果您忘记了该秘密,那么您将需要生成一个新的秘密并更新使用该秘密的所有位置。理想情况下,您希望将其存储在Azure Vault 中,以便您的应用和流可以从那里读取它。

App注册中的API权限

在我们的应用程序注册中,我们现在可以设置 API 权限。

您现在可以选择 Microsoft Graph 或您需要访问的任何其他 API。但是请将您设置的权限限制在小范围内。创建应用程序注册以访问多个 API 或 Mcirosoft Graph 的大部分通常不是一个好主意。

默认情况下,应用程序会获得 User.Read 权限。

现在我们需要做出决定的下一步。使用委派权限或应用程序权限。

Then after that we can select the areas within the Graph APIs that you need access to using your flow or app.

In my case I’m going to give the app Delegated permissions to Directory.Read.All and User.Read.All. Then my flow can read the user details from Azure Azctive Directory.

Back to Power Automate and the Microsoft Graph API

Using all the information that we collected so far we can now make the Microsoft Graph API call work.

Now when I run my flow the step will be running successfully.

Power Apps and the Microsoft Graph API

So we have made the Microsoft Graph API work within a flow in Power Automate. And Although we could now call flows from the apps, we might want to call the Graph API directly from our app without calling a flow.

Is this possible?

There is no HTTP request datasource available within Power Apps.

How about using the Office 365 Users connector? Well these actions can indeed be used, however the calls made will always return just true when the call is made.

There is a way to fix this explained by Deepak in an excellent video, however you can’t do this directly from the Power Apps Studio UI.

Before jumping onto this idea you might still want to consider using flows to call the Microsoft Graph API as it will be easier to manage.

Coming soon

So far I’ve gone through using the Graph API within Power Automate and Power Apps. The next step is to look at the various calls that you can make and how the Graph API can help you with your app and flow development.

As promised this is a series of posts. I will look at each area of the Microsoft Graph API and explain how to use the various API endpoints. As the posts arrive I will include the links here.

Other posts in this series

Some of the Microsoft Graph API related posts you can find here:

SharePoint/Excel

Graph API and SharePoint

SharePoint Enterprise Content Types and the Graph API

Power Automate – Read large Excel files within seconds without creating tables using Microsoft Graph

Populate 1 Excel template faster with Power Automate

Performance of the Graph API, REST API and Web Services with SharePoint and Power Automate

Users

Manage Users using the Graph API in Power Automate

Calendars and events

Manage Calendars and Events using Microsoft Graph in Power Automate

Subscriptions

Subscribe to Microsoft Graph using Power Automate

Filter and Select data in Microsoft Graph

Filter and Select data in Microsoft Graph

Microsoft Teams and One on One Chats

Get One on One chats from Microsoft Teams in Power Automate

Device Management

Lock and wipe devices using Microsoft Graph

Share this:

Like this:

Like Loading...

Related

How to use Microsoft Graph for SharePoint within Power Automate

In this post a variety of options on how to use Microsoft Graph for SharePoint within Power Automate. My Microsoft Graph Series, so far I will start with a quick overview of the Microsoft Graph posts that I published recently. MS Graph API Authentication in Introduction Manage Users with the…

In "Microsoft Graph"

Get your Microsoft Teams One on One chats with Power Automate using the Graph API

You can get some details of One on One chats in Microsoft Teams using the Microsoft Teams connector in Power Automate, but getting the actual details is slightly harder. Chats and the Teams Connector Using the List chats action you can choose to get chats of the different types available.…

In "Microsoft Graph"

在 Power Automate 中从 Microsoft Graph 筛选和选择数据的 2 种方法

在我关于 Power Platform 中的 Microsoft Graph 的系列文章中,我使用客户连接器和 HTTP 操作收集了数据,但我们如何在 Microsoft Graph 中筛选和选择数据?过滤操作 要过滤返回的数据,我们可以使用过滤操作。但这意味着……

在“微软图表”中

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
微软Power Platform展现战略雄心:让天下没有难做的APP
Comparing Excel Automation to Excel Services
ASP.NET Core minimal web API that both protects its own endpoints and accesses Microsoft Graph.
2015年浙江卷高考英语试题及答案详解
Microsoft API and Reference Catalog
怎样将PPT转换成word
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服