简体   繁体   English

获取扩展属性Microsoft graph JavaScript API

[英]Get extended property Microsoft graph javascript api

I have assigned extended property to my primary calendar and im trying to retrieve that but im not getting it to work. 我已将扩展属性分配给我的主日历,并且我试图检索该属性,但无法使其正常工作。

The docs im following is graph api and javascript sdk 以下文档即时消息是图形APIJavaScript SDK

function postUserCalendar(emailAddress) {
var rand = guid();
const values = {
  MultiValueExtendedProperties: [{
    PropertyId: 'StringArray ' + '{' + rand + '}' + ' Name Palette',
    Value: ["Green", "Aqua", "Blue"]
  }]
};
getAccessToken(function(accessToken) {
  if (accessToken) {
    var client = MicrosoftGraph.Client.init({
      authProvider: (done) => {
        done(null, accessToken);
      }
    });
    client
      .api('me/calendars/myCalendarId')
      .header('Accept','application/json')
      .patch({
        message: values
      }, (err, res) => {
        console.log(err);
        console.log(res);
      });
  } else {
    var error = {
      responseText: "Cound not retrieve access token"
    };

  }
 });
}

Above is my function to set MultiValueExtendedProperties. 上面是我设置MultiValueExtendedProperties的函数。 Then i have a function where i try to retrieve those properties. 然后我有一个函数,我尝试检索这些属性。

  function getUserCalendar(emailAddress, callback) {
getAccessToken(function(accessToken) {
  if (accessToken) {
    // Create a Graph client
    var client = MicrosoftGraph.Client.init({
      authProvider: (done) => {
        // Just return the token
        done(null, accessToken);
      }
    });
    client
      .api('/me/calendars/myCalendarId')
      .header('X-AnchorMailbox', emailAddress)
      .expand('multiValueExtendedProperties')
      .filter('id eq {c56fe371-87fb-87a8-1727-9b2b272b9f76}')
      .get((err, res) => {
        if (err) {
          callback(null, err);
        } else {
          callback(res.value);
        }
      });
  } else {
    var error = {
      responseText: 'Could not retrieve access token'
    };
    callback(null, error);
  }
 });
}

The get request has a status of 200 but i get a jquery error "a is not defined" get请求的状态为200,但出现jquery错误“未定义”

If someone can point me in the right direction i would appreciate it. 如果有人能指出我正确的方向,我将不胜感激。

Thanks! 谢谢!

There's a few mistakes in your code that are causing problems. 您的代码中有一些错误会导致问题。

Patching the calendar 修补日历

Here you pass {message: values} as the first parameter to patch , which causes incorrect JSON to be passed in the payload. 在这里,您将{message: values}作为patch的第一个参数传递,这将导致在有效负载中传递不正确的JSON。 You should just pass values itself, which will serialize correctly: 您应该只传递值本身,它将正确序列化:

client
    .api('me/calendars/myCalendarId')
    .header('Accept','application/json')
    .patch(values, (err, res) => {
        console.log(err);
        console.log(res);
     });

Getting the calendar with property expanded 扩展带有属性的日历

Here you don't want to use the filter method from the SDK. 在这里,您不想使用SDK中的filter方法。 That adds a filter clause to the GET, instead of adding a filter to the expand , which is what you want. 这会将过滤器子句添加到GET,而不是将过滤器添加到expand ,这是您想要的。 Instead, embed the filter in the string passed to expand , like so: 而是将过滤器嵌入传递给expand的字符串中,如下所示:

client
    .api('/me/calendars/myCalendarId')
    .header('X-AnchorMailbox', emailAddress)
    .expand("multiValueExtendedProperties($filter=id%20eq%20'StringArray%20{66f5a359-4659-4830-9070-00050ec6ac6e}%20Name%20Palette')")
    .get((err, res) => {
        if (err) {
            callback(null, err);
        } else {
            callback(res);
        }
    });

Consider using open extensions instead 考虑改用开放扩展

We recommend using open extensions for storing custom data instead of legacy extended properties. 我们建议使用开放扩展名来存储自定义数据,而不要使用旧版扩展属性。 Open extensions are more flexible and easier to work with. 开放式扩展更灵活,更易于使用。 Unless there's some compelling reason you need it to be a legacy property (like backwards-compat with an existing solution, etc.), I'd recommend open extensions. 除非有某些令人信服的理由,否则您需要将其作为遗留属性(例如与现有解决方案向后兼容等),否则我建议您使用开放扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM