⚙
Webhook
Run a notebook by calling an URL.
Send in production this notebook and get URL to run it when opened.
naas.webhook.add()

screenshot-api-add
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")
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)
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.

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

Need to understand why somethings go bad?
naas.webhook.add(debug=True)
Run a Notebook by API is not enough, you can return a result :
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.
naas.webhook.respond_json({"foo": "bar"})
import requests
url = "https://picsum.photos/id/237/200/300"
naas.webhook.respond_image(requests.get(url, stream=True).content)
# 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)
# Exemple text
text = "Hello Naas friends, do you love markdown as us ?"
naas.webhook.respond_text(markdown_text)
# Exemple MD
markdown_text = "# Hello Naas friends<br /> Do you love markdown as us ?"
naas.webhook.respond_markdown(markdown_text)
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)
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.
Respond the notebook output with:
naas.webhook.respond_notebook()
You can find URL of a file pushed into the production:
url = naas.webhook.find()
url = naas.webhook.find(path="path/to/my/super/notebook.ipynb")
You can list all version of a file pushed into the production:
naas.webhook.list()
naas.webhook.list(path="path/to/my/super/notebook.ipynb")
You can get a version of a file pushed into the production:
naas.webhook.get()
naas.webhook.get(path="path/to/my/super/notebook.ipynb")
naas.webhook.get(histo="20201008101221879662")
naas.webhook.get(path="path/to/my/super/notebook.ipynb", histo="20201008101221879662")
You can clear the previous version of a file pushed into the production:
naas.webhook.clear(histo="20201008101221879662")
naas.webhook.clear(path="path/to/my/super/notebook.ipynb", histo="20201008101221879662")
naas.webhook.clear()
naas.webhook.clear(path="path/to/my/super/notebook.ipynb")
You can get the output of the production file:
naas.webhook.get_output()
naas.webhook.get_output(path="path/to/my/super/notebook.ipynb")
You can clear the previous output of a file pushed into the production:
naas.webhook.clear_output()
naas.webhook.clear_output(path="path/to/my/super/notebook.ipynb")
You can remove any scheduler capability like that, it takes optionally a path.
naas.webhook.delete()
naas.webhook.delete(path="path/to/my/super/notebook.ipynb")
naas.webhook.delete(debug=True)
You don't remember how many API notebooks you have?
naas.webhook.currents()
naas.webhook.currents(raw=True)
Last modified 1yr ago