i'm using Microsoft Graph in my Laravel application.
It works perfectly adding events to the user's calendar, getting events, creating OneNote's notebook.
The problem occurs when i try to add a page, i'm getting the next error:
The code i'm using is:
public function createNewNote()
{
$graph = $this->getGraph();
// Build the event
$newEvent = [
'body' => [
'content' => 'New page in default notebook',
'contentType' => 'text/html'
]
];
// POST /me/onenote/notebooks DEFAULT NOTEBOOK
$response = $graph->createRequest('POST', '/me/onenote/pages')
->attachBody($newEvent)
->setReturnType(Model\Notebook::class)
->execute();
dd("Success");
// return redirect('/calendar');
}
The next code works fine:
public function createNewNotebook()
{
$graph = $this->getGraph();
$newEvent = [
'displayName' => 'Creating new notebook'
];
// POST /me/onenote/notebooks DEFAULT NOTEBOOK
$response = $graph->createRequest('POST', '/me/onenote/notebooks')
->attachBody($newEvent)
->setReturnType(Model\Notebook::class)
->execute();
dd("Notebook Created");
// return redirect('/calendar');
}
public function createNewNote()
{
$graph = $this->getGraph();
// POST /me/onenote/notebooks DEFAULT NOTEBOOK
$response = $graph->createRequest('POST', '/me/onenote/pages')
->attachBody('<div>Content</div>')
->setReturnType(Model\Notebook::class)
->execute();
dd("Success");
// return redirect('/calendar');
}
Thank you so much for your help!
As specified in the document since you are putting the HTML data in attachBody
directly without specifying the content type.
That's the reason the other API calls work as they have JSON data specified properly.
As specified here in the example they have specified the content type.
I have tested the same with POSTMAN as shown below where you can see the content-type I have mentioned as text/html
as the content we give is a div tag and it worked.