# How to save Jupyter notebook via API?

**URL:** <https://discourse.jupyter.org/t/how-to-save-jupyter-notebook-via-api/2541>\
**Category:** Notebook\
**Created:** [October 27, 2019, 8:12am UTC](https://discourse.jupyter.org/t/how-to-save-jupyter-notebook-via-api/2541 "2019-10-27T08:12:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![takiholadi](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@takiholadi](https://discourse.jupyter.org/u/takiholadi)\
**Post date:** [October 27, 2019, 8:12am UTC](https://discourse.jupyter.org/t/how-to-save-jupyter-notebook-via-api/2541/1 "2019-10-27T08:12:17Z")

</div>

Good day!

Is it possible to achieve “File” → “Save and Checkpoint” programmatically?

I know there is JS command, but it has no callback and so I can’t be sure that file is actually saved.

I also found “Save file” section in Jupyter APIs:

> **[Jupyter Notebook Server API](https://github.com/jupyter/jupyter/wiki/Jupyter-Notebook-Server-API#notebook-and-file-contents-api)**
>
> Jupyter metapackage for installation, docs and chat - jupyter/jupyter

Tried without success:

> import requests  
> response = requests.request(  
> method=‘PUT’,  
> url=‘[http://127.0.0.1:8888/api/contents/my-notebook.ipynb](http://127.0.0.1:8888/api/contents/my-notebook.ipynb)’,  
> headers={‘Authorization’: ‘token 6ec2282d28e6e755629e9007787299a929a0154e54c59df7’},  
> )  
> print(response.status\_code)  
> print(response.json())

Don’t you know is it possible to achieve this?

---

<div class="post-metadata">

**Author:** ![00Kai0](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/00kai0/32/1144_2.png) [@00Kai0](https://discourse.jupyter.org/u/00Kai0)\
**Post date:** [October 27, 2019, 3:40pm UTC](https://discourse.jupyter.org/t/how-to-save-jupyter-notebook-via-api/2541/2 "2019-10-27T15:40:44Z")

</div>

This is helpful.  
[https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html](https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html)

Maybe some error in your put data. put data is content which will be used in `ContentManager`.

---

<div class="post-metadata">

**Author:** ![takiholadi](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@takiholadi](https://discourse.jupyter.org/u/takiholadi)\
**Post date:** [December 2, 2019, 12:23pm UTC](https://discourse.jupyter.org/t/how-to-save-jupyter-notebook-via-api/2541/3 "2019-12-02T12:23:26Z")

</div>

> [@00Kai0](#):
>
> in your put data. put data is content which will be used in `C`

@00Kai0 Could you specify more details pls?

---

<div class="post-metadata">

**Author:** ![00Kai0](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/00kai0/32/1144_2.png) [@00Kai0](https://discourse.jupyter.org/u/00Kai0)\
**Post date:** [December 3, 2019, 2:46am UTC](https://discourse.jupyter.org/t/how-to-save-jupyter-notebook-via-api/2541/4 "2019-12-03T02:46:08Z")

</div>

This is the JS code in jupyternotebook:

```javascript
    Contents.prototype.save = function(path, model) {
        /**
         * We do the call with settings so we can set cache to false.
         */
        var settings = {
            processData : false,
            type : "PUT",
            dataType: "json",
            data : JSON.stringify(model),
            contentType: 'application/json',
        };
        var url = this.api_url(path);
        return utils.promising_ajax(url, settings);
    };

```

The problem is that you need put `data` in your request.The API will use `ContentsManager.save(model, path)` to save file. Your need know how to decode an .ipynb to a model, then change something in it, at last put your model to Save API to save .ipynb file.
