使用 teamsfx 调用动态全局发现服务

huangapple go评论69阅读模式
英文:

Use teamsfx to call dynamics global discovery service

问题

我正在尝试在我的React Tab Teams应用中使用Teams来调用动态全局发现API。

我可以在Postman上按照这里的指南使其工作:https://learn.microsoft.com/en-gb/power-apps/developer/data-platform/discovery-service?WT.mc_id=ppac_inproduct_legacy 但是,当我尝试通过Teamsfx在我的Teams React应用中调用API时,我得不到任何返回,但我收到了一个200成功代码。我已经按照以下方式实施了调用。

await teamsUserCredential.login(["User.Read", "https://globaldisco.crm.dynamics.com/user_impersonation"]);
const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', { 
  headers: { 
    Authorization: `Bearer ${accessToken.token}`, 
  }
});

我还在应用注册中授予了管理员权限,但是我是否正确地说这在技术上不是必要的,因为登录函数应该在用户级别请求权限?

任何帮助让我开始并能够调用全局发现API都将不胜感激。

英文:

I am trying to use teams to call the dynamics global discovery API on my react tab teams app.

I can get it working on postman following the guide here: https://learn.microsoft.com/en-gb/power-apps/developer/data-platform/discovery-service?WT.mc_id=ppac_inproduct_legacy however, when I try to call the API through teamsfx on my teams react app I am getting nothing back, but I am getting a 200 success code. I have implemented the the call as below.

  await teamsUserCredential.login(["User.Read","https://globaldisco.crm.dynamics.com/user_impersonation"]);
  const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
  const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', { 
    headers: { 
      Authorization: `Bearer ${accessToken.token}`, 
    }
  });

I have also granted admin permission on the app registration, however am I right in saying this is not technically necessary as the login function should ask for permission at a user level?

使用 teamsfx 调用动态全局发现服务

Any help in getting me up and running so I can call the global discovery API would be much appreciated.

答案1

得分: 0

I tested using Postman and code, and it seems to be the fetch part.

From postman:

GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances

使用 teamsfx 调用动态全局发现服务

After updating the fetch to code attached below, you should be able to get the data as shown in Postman:

const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', { 
  headers: { 
    Authorization: `Bearer ${accessToken!.token}`, 
  }
}).then((response) =>{
  if (!response.ok) {throw new Error(`HTTP error! Status: ${response.status}`)}
  return response.json();
}).then(data => {return data});

使用 teamsfx 调用动态全局发现服务

英文:

I tested using Postman and code, and it seems to be the fetch part.

From postman:

GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances

使用 teamsfx 调用动态全局发现服务

After updating the fetch to code attached below, you should be able to get the data as shown in Postman:

const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', { 
  headers: { 
    Authorization: `Bearer ${accessToken!.token}`, 
  }
}).then((response) =>{
  if (!response.ok) {throw new Error(`HTTP error! Status: ${response.status}`)}
  return response.json();
}).then(data => {return data});

使用 teamsfx 调用动态全局发现服务

huangapple
  • 本文由 发表于 2023年7月12日 23:51:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76672414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定