首页 > 解决方案 > 尝试通过 v2.0 REST API 获取不可变 ID

问题描述

我正在开发一个 Outlook 插件(目前在网络上进行测试)我需要获取一些不可变的 ID,以便我可以在我们的平台上存储对这些电子邮件的引用。我读到了 Outlook 团队的这篇很棒的回复,并且整天都在尝试调用 translateExchangeIds,但没有成功。首先,我真的找不到说明这个端点实际上存在于 REST v2.0 API 上的文档。我可以说它确实存在,因为如果我稍微更改 json 对象的大小写,我会收到错误消息,指出有效负载与端点所说的不匹配。我目前遇到错误

code: "ErrorAccessDenied" message: "Access is denied. Check credentials and try again."

这似乎很明显我应该做的是检查我的权限。我可以找到的文档提到我需要 User.ReadBasic。不过,这确实不是我为 Outlook 插件定义权限的方式。在我添加的 manifest.xml 文件中,我定义了权限

 <Permissions>ReadWriteMailbox</Permissions>

这应该足以调用此端点

const getImmutableId = async () => new Promise<string>((resolve) => {
  Office.context.mailbox.getCallbackTokenAsync(
    { isRest: true },
    (result: Office.AsyncResult<string>) => {
      const headers = new Headers();
      headers.append('Authorization', `Bearer ${result.value}`);
      headers.append('content-type', 'application/json');
      headers.append('data-type', 'json');
      headers.append('process-data', 'false');
      fetch(`${Office.context.mailbox.restUrl}/v2.0/me/translateExchangeIds`, {
        headers,
        method: 'POST',
        body: JSON.stringify({
          InputIds: [
            Office.context.mailbox.item.itemId,
          ],
          SourceIdType: 'ewsId',
          TargetIdType: 'restImmutableEntryId',
        }),
      }).then((response: Response) => {
        if (response.ok) {
          response.json().then((restResponse: {targetId: string, sourceId: string}[]) => {
            resolve(restResponse[0].targetId);
          });
        } else {
          // eslint-disable-next-line no-console
          console.warn('there was a failire to get an immutable id falling back to mutable rest id');
          resolve(Office.context.mailbox.convertToRestId(
            Office.context.mailbox.item.itemId, Office.MailboxEnums.RestVersion.v2_0,
          ));
        }
      });
    },
  );
});

任何帮助将不胜感激。

标签: office-jsoutlook-addinoutlook-web-addins

解决方案


您阅读的 StackOverflow 帖子(链接)指出示例代码不完整,因为getAccessTokenAsyncAPI 调用提供的令牌缺少REST APIUser.ReadBasic.All所需的权限。translateExchangeIds有一篇关于不可变 ID的现有UserVoice 帖子。请在那里添加你的声音。当我们进行规划过程时,会考虑用户语音的功能请求。


推荐阅读