Mathieu
Mathieu

Reputation: 11

Microsoft Graph with OneDrive API, invite : fail with Unsupported segment type

Using jquery, I've managed so far to send a Copy Item request( POST /me/drive/items//copy), however if I try to add permission ( POST /drive/items//invite), I receive the "Unsupported segment type" error.

The API documentation : graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_invite

(I copied the two function to compare)

 // working:
    copyFile:function(id, folderId){
            // https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_copy
            // POST /me/drive/items/<id>/copy
            var endpointUrl = 'https://graph.microsoft.com/v1.0/me/drive/items/'+id+'/copy';
            var data={};
            data.parentReference={'id':folderId}
            $.ajax({
                 beforeSend: function(xhrObj){
                    xhrObj.setRequestHeader("Content-Type","application/json");
                    xhrObj.setRequestHeader("Accept","application/json");
                },
                processDate: false,
                datatype : "json",
                method: "POST",
                //http://stackoverflow.com/questions/13956462/jquery-post-sends-form-data-and-not-json 
                data: JSON.stringify(data),
                url: endpointUrl,
                contentType : 'application/json',
                headers : { "authorization" : "Bearer " + token }
            }).success(function(data) {
                alert('success!')
            });
        },

    ///NO WORKING ?
    invite:function(id, user){
        // http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_invite
        // POST /drive/items/<id>/invite
        var endpointUrl = 'https://graph.microsoft.com/v1.0/drive/items/'+id+'/invite';

        data={
            "requireSignIn": true,
            "sendInvitation": false,
            "roles": "read",
            "recipients": [  { "email": user }],
            "message": "NO MESSAGE ?"   
        }
        $.ajax({
            beforeSend: function(xhrObj){
                xhrObj.setRequestHeader("Content-Type","application/json");
                xhrObj.setRequestHeader("Accept","application/json");
            },
            datatype : "json",
            method: "POST",
            data: JSON.stringify(data),
            url: endpointUrl,
            contentType : 'application/json',
            headers : {"authorization" : "Bearer " + token}
        }).success(function(data) {
            alert( 'success!')
        });

API return:

{
  "error": {
    "code": "BadRequest",
    "message": "Unsupported segment type. ODataQuery: drive/items/***********/invite",
    "innerError": {
      "request-id": "********",
      "date": "2016-09-14T09:01:32"
    }
  }
}

Did I miss something ?

Upvotes: 0

Views: 595

Answers (1)

Mathieu
Mathieu

Reputation: 11

It seems the v1.0 version does not currently works. I swapped to beta, using this url:

var endpointUrl = 'https://graph.microsoft.com/beta/me/drive/items/'+id+'/invite';

And it works

Upvotes: 1

Related Questions