Links

Webhook

Run a notebook by calling an URL.

Add

Send in production this notebook and get URL to run it when opened.
naas.webhook.add()
screenshot-api-add

Other files

You can also give a path to the function and that will deploy this one instead of the current one.
naas.webhook.add(path="path/to/my/super/notebook.ipynb")

Parameters

notif_down : Receive an email when the notebook run fails.
notif_up : Receive an email when the notebook runs well.
next_url : Redirect users to another URL after the notebook is run.
inline : Get a response in your web browser instead of downloading the result.
params = {"notif_down": "[email protected]", "notif_up": "[email protected]"}
naas.webhook.add(params=params)

Dynamic Parameters

When you notebook url is called in getting or post, it accepts parameters with mime-type :
application/x-www-form-urlencoded
application/json
They will be injected into a new cell in the first position in your notebook.
If You want them to be added at a specific place add tag parameters in a cell and your dynamic parameters will be added in a new cell next to it.

Example of params

In this screenshot below, you can see variables from our notebook in the first cell, and in the second cell, the dynamic parameters injected.

Debug

Need to understand why somethings go bad?
naas.webhook.add(debug=True)

Response

Run a Notebook by API is not enough, you can return a result :

Html

Send back any HTML payload.
Don't be a fool and put Facebook code source here, the idea is to stay simple!
naas.webhook.respond_html("<h1>Check my super html !</h1>")
To confirm that is well loaded you should see it in the cell output.

JSON

naas.webhook.respond_json({"foo": "bar"})

Image

import requests
url = "https://picsum.photos/id/237/200/300"
naas.webhook.respond_image(requests.get(url, stream=True).content)

SVG

# Exemple Svg
jupyterlogo = '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Jupyter icon</title><path d="M7.157 22.201A1.784 1.799 0 0 1 5.374 24a1.784 1.799 0 0 1-1.784-1.799 1.784 1.799 0 0 1 1.784-1.799 1.784 1.799 0 0 1 1.783 1.799zM20.582 1.427a1.415 1.427 0 0 1-1.415 1.428 1.415 1.427 0 0 1-1.416-1.428A1.415 1.427 0 0 1 19.167 0a1.415 1.427 0 0 1 1.415 1.427zM4.992 3.336A1.047 1.056 0 0 1 3.946 4.39a1.047 1.056 0 0 1-1.047-1.055A1.047 1.056 0 0 1 3.946 2.28a1.047 1.056 0 0 1 1.046 1.056zm7.336 1.517c3.769 0 7.06 1.38 8.768 3.424a9.363 9.363 0 0 0-3.393-4.547 9.238 9.238 0 0 0-5.377-1.728A9.238 9.238 0 0 0 6.95 3.73a9.363 9.363 0 0 0-3.394 4.547c1.713-2.04 5.004-3.424 8.772-3.424zm.001 13.295c-3.768 0-7.06-1.381-8.768-3.425a9.363 9.363 0 0 0 3.394 4.547A9.238 9.238 0 0 0 12.33 21a9.238 9.238 0 0 0 5.377-1.729 9.363 9.363 0 0 0 3.393-4.547c-1.712 2.044-5.003 3.425-8.772 3.425Z"/></svg>'
naas.webhook.respond_svg(jupyterlogo)

Text

# Exemple text
text = "Hello Naas friends, do you love markdown as us ?"
naas.webhook.respond_text(markdown_text)

Markdown

# Exemple MD
markdown_text = "# Hello Naas friends<br /> Do you love markdown as us ?"
naas.webhook.respond_markdown(markdown_text)

CSV

Again, this is not intended to host a 6Go CSV file, it will break your notebook and you will lose access to it, use the "File" option instead.
# Exemple Csv
csv_text = ```
Sally Whittaker,2018,McCarren House,312,3.75
Belinda Jameson,2017,Cushing House,148,3.52
Jeff Smith,2018,Prescott House,17-D,3.20
Sandy Allen,2019,Oliver House,108,3.48
```
naas.webhook.respond_csv(csv_text)

File

Send big file not embed in the notebook :
naas.webhook.respond_file("test.csv")
If your file is not generated by a notebook, add it as Dependency, otherwise, it will be missing in the production folder.

Notebook

Respond the notebook output with:
naas.webhook.respond_notebook()

Find

You can find URL of a file pushed into the production:

Current file

url = naas.webhook.find()

Other files

url = naas.webhook.find(path="path/to/my/super/notebook.ipynb")

List

You can list all version of a file pushed into the production:

Current file

naas.webhook.list()

Other files

naas.webhook.list(path="path/to/my/super/notebook.ipynb")

Get

You can get a version of a file pushed into the production:

Get the last one

naas.webhook.get()

With a file path

naas.webhook.get(path="path/to/my/super/notebook.ipynb")

With history id

naas.webhook.get(histo="20201008101221879662")

Combined

naas.webhook.get(path="path/to/my/super/notebook.ipynb", histo="20201008101221879662")

Clear

You can clear the previous version of a file pushed into the production:

One

naas.webhook.clear(histo="20201008101221879662")

Other Notebook

naas.webhook.clear(path="path/to/my/super/notebook.ipynb", histo="20201008101221879662")

All

naas.webhook.clear()

All for filepath

naas.webhook.clear(path="path/to/my/super/notebook.ipynb")

Get output

You can get the output of the production file:

Get the last one

naas.webhook.get_output()

With a file path

naas.webhook.get_output(path="path/to/my/super/notebook.ipynb")

Clear output

You can clear the previous output of a file pushed into the production:

One

naas.webhook.clear_output()

Other Notebook

naas.webhook.clear_output(path="path/to/my/super/notebook.ipynb")

Delete

You can remove any scheduler capability like that, it takes optionally a path.

Current

naas.webhook.delete()

Other file

naas.webhook.delete(path="path/to/my/super/notebook.ipynb")

Debug

naas.webhook.delete(debug=True)

List APIs

You don't remember how many API notebooks you have?

Simple

naas.webhook.currents()

Raw result

naas.webhook.currents(raw=True)
Last modified 1yr ago