1

I am trying to delete an event using Microsoft Graph API.

My issue is that I couldn't delete an event even the response returns success. (regarding the official doc, success returns null)

My technical stack is CakePHP v4.x and I code like the following.

$http = new Client();
$appToken = $this->getRequest()->getSession()->read('appToken');

if ($this->request->is('ajax')) {
    $this->autoRender = false;
}

$url = "https://graph.microsoft.com/v1.0/users/{user-id}/calendar/events/{event-id}";
$response_delete = json_decode($http->delete($url, [], [
            'headers' => ['Authorization' => 'Bearer '. $appToken]
        ])->getBody()->getContents(), true);
// $response_delete = null

$appToken is the application token so a company user can delete an event.

The token works fine and also I already have the full permissions on Azure active directory.

But real strange thing is that the same code works properly on my local side.

I merged my all updated codes using Git and compared the codebase several times, but I didn't have any luck.

I am not sure why it does happen.

Thanks in advance.

UPDATE: The application token enter image description here

hotcakedev
  • 2,194
  • 1
  • 25
  • 47
  • (1) Check the token using https://jwt.ms and see whether the logged user has necessary permissions to delete the item. If permission doesnt exists then provide and give a try (2) To isolate the issue outside of your code, try the above call in Microsoft Graph explorer or POSTMAN and see if you can repro the issue. – Dev Apr 28 '21 at 04:18
  • @Dev, Thanks. Regarding my test on postman, it responses `Access token has expired or is not yet valid.`. But it doesn't make any sense because I am sure that the app token is correct. Is the app token able to be different between staging and local environment? It's so weird. – hotcakedev Apr 28 '21 at 04:44
  • Exactly this was i suspected. Please get the access token or get a new refresh token if the access token is expired, then use it and try repro the issue. – Dev Apr 28 '21 at 05:03
  • @Dev, Could you let me know why this happens. This is odd because both application token and access token are still valid. – hotcakedev Apr 28 '21 at 08:34
  • @Dev No... It worked fine on postman. It responses empty. My fault was not using `Bearer ` for the front of app token. So the app token is valid, but still not working. – hotcakedev Apr 28 '21 at 08:40
  • The application token does not have a refresh token. Can you parse the token and upload a screenshot? – Carl Zhao Apr 28 '21 at 09:24
  • @CarlZhao Can you see my updates? – hotcakedev Apr 28 '21 at 09:31
  • 1
    @hotcakedev I saw it, and your token looks okay. Give me some time and I will test it. – Carl Zhao Apr 28 '21 at 09:49
  • @CarlZhao Thanks, and as I mentioned, deleting an event works on my local side, but it doesn't work on the staging nginx server. – hotcakedev Apr 28 '21 at 11:31
  • Other Graph operations also fail on the staging nginx server? – Allen Wu Apr 29 '21 at 02:27
  • @AllenWu, Absolutely not. Everything works fine except the delete API. – hotcakedev Apr 29 '21 at 02:40
  • 1
    I would double check whether the above graph api call works from the given server using Graph explorer or not (outside of your application) to confirm whether it works correctly, receives back the info from Microsoft Cloud. – Dev Apr 29 '21 at 10:45
  • @Dev, Do you have any advance? – hotcakedev Apr 30 '21 at 17:14
  • @hotcakedev - i suggested the above action plan to you and test it in the above given server to check whether you can get the data correctly or not. I dont have the environment, but when i tested at my end with my test bed, the above calls worked for me. – Dev Apr 30 '21 at 17:50
  • That's weird. Deleting an event works properly on both local and postman with the same token. But it doesn't work on the server. – hotcakedev May 19 '21 at 19:10

0 Answers0