1
votes

My goal is to use client credentials and Graph subscriptions for messages, for several users in my tenant.

I'm successfully getting the access token via client credentials, and can use it with Graph for things like creating calendar events for multiple users.

However, when I use the access token to create a Graph subscription for messages, I get a failure of "Unsupported segment type".

Does graph support client credentials for subscriptions? If yes, am I doing something wrong?

Thanks for any help.

"error": {
    "code": "BadRequest",
    "message": "Unsupported segment type. ODataQuery: users//subscriptions",
    "innerError": {
        "request-id": "e92caf14-0343-40b0-8720-30946d7fd236",
        "date": "2018-05-17T17:53:34"
    }
}

Here's my subscribe function:

graph.subscribe = function(token, userid) {

  var subscription = {
    changeType: 'Created',
    notificationUrl: 'my notification url',
    resource: '/users/<userid removed>/messages',
    clientState: 'blah'
  };

  request.post({
    url: 'https://graph.microsoft.com/v1.0/users/<userid removed>/subscriptions',
    headers: {
      'content-type': 'application/json',
      authorization: 'Bearer ' + token
    },
    body: JSON.stringify(subscription)
  }, function(err, response, body) {
    if (err) {
      console.error('>>> Application error: ' + err);
    } else {
      console.log('>>> Subscription returned ' + body);
    }
  });
};
1

1 Answers

0
votes

The POST should be issued to the /v1.0/subscriptions endpoint, not /v1.0/users/{upn}/subscriptions.

You may want to take a look at this Node.js example to see how they're doing it.