Search code examples
office365onenoteonenote-api

How to Delete and Rename Notebook name Using Onenote Graph API


I want to rename notebook name. i tried below Graph request.

PATCH "graph.microsoft.com/v1.0/me/onenote/notebooks{id}" 

I am getting "UnknownError", What is PATCH Request url to rename notebook?


Solution

  • OneNote Notebooks are folders when exposed to the OneDrive api and can be renamed or deleted.

    The OneDrive documentation, however, specifically suggests not doing this with OneNote Notebooks.

    sample php code to delete NoteBook (you would obtain {item-id} via https://graph.microsoft.com/v1.0/me/drive/root/children)

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,
        'https://graph.microsoft.com/v1.0/me/drive/items/{item-id}');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST => 'DELETE');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: */*',
        'return-client-request-id: true','Content-Type: application/json',
        'Authorization: Bearer eyJ0eXAiOiJKV1Qi…));
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
    

    The deleted Notebook is moved to the Recycle bin.

    sample php code to rename NoteBook

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,
        'https://graph.microsoft.com/v1.0/me/drive/items/{item-id}');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST => 'PATCH');
    curl_setopt($ch, CURLOPT_POSTFIELDS,'{"name":"newname"}');  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: */*',
        'return-client-request-id: true','Content-Type: application/json',
        'Authorization: Bearer eyJ0eXAiOiJKV1Qi…));
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;