diff --git a/Naas Credits/Naas_Credits_Export_current_transaction.ipynb b/Naas Credits/Naas_Credits_Export_current_transaction.ipynb new file mode 100644 index 0000000000..9294494d14 --- /dev/null +++ b/Naas Credits/Naas_Credits_Export_current_transaction.ipynb @@ -0,0 +1,252 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "168abe1a-0f00-446c-bd08-74b5cb43c4a4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "d42f1fdd-8fd8-4213-8e15-78f6281e6344", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Naas Credits - Export current transaction" + ] + }, + { + "cell_type": "markdown", + "id": "09160566-d6dd-4912-8aa4-df8f40036d72", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #naascredits #export #transaction #current #python #notebook" + ] + }, + { + "cell_type": "markdown", + "id": "026cfb17-7b38-4ebb-ae40-8147b11a6ab6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "cfe15482-7cfe-4de2-a83f-e91aeffa3e3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-12-21 (Created: 2023-12-21)" + ] + }, + { + "cell_type": "markdown", + "id": "fce74c2a-914f-47d8-acef-dadce3d4da59", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook will export the current transaction from Naas Credits. It will allow to have a better understanding of the current transaction and to analyze it." + ] + }, + { + "cell_type": "markdown", + "id": "2c60ac49-a891-462d-86ae-5890bb801ab8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n- [Naas Credits Documentation](https://docs.naascredits.com/)\n- [Naas Credits API Reference](https://api.naascredits.com/reference)" + ] + }, + { + "cell_type": "markdown", + "id": "1de76aea-f175-4f80-b0de-f827518a47b6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "0eab4379-7117-468a-86e9-5ec4701d1a00", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7f994733-0621-4cce-8fda-f1a3cc2ee3d2", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "import requests\nimport json", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "367bb25c-0161-47b9-9514-611399f0d510", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- **api_key**: API key provided by Naas Credits. [How to get an API key?](https://docs.naascredits.com/getting-started/api-key)\n- **transaction_id**: ID of the transaction to be exported" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "349d0cbe-c9fb-48e6-be73-ad5c0911839a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "api_key = \"YOUR_API_KEY\"\ntransaction_id = \"YOUR_TRANSACTION_ID\"", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "3af3ebc4-3b52-4cc4-8974-3d222a1cb0b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "9445fab9-f0ac-4af5-b3d3-d4990137f9d4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Export current transaction" + ] + }, + { + "cell_type": "markdown", + "id": "3f55d120-d3cc-441e-b928-69081078eb87", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "This function will export the current transaction from Naas Credits." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "06a55817-cb91-4f9f-ae7e-25595be18237", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "def export_transaction(api_key, transaction_id):\n url = \"https://api.naascredits.com/v1/transactions/\" + transaction_id\n headers = {\"Authorization\": \"Bearer \" + api_key}\n response = requests.get(url, headers=headers)\n if response.status_code == 200:\n return json.loads(response.content.decode(\"utf-8\"))\n else:\n return None", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "775fe31b-d335-4b03-92e5-ed11f25f953e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "9e8ea457-99a5-40ff-ac9b-28f195511068", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb2a040e-dd00-4afa-933b-9ea2497d83dc", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "transaction = export_transaction(api_key, transaction_id)\nif transaction is not None:\n print(json.dumps(transaction, indent=4))\nelse:\n print(\"Error while exporting transaction\")", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "e71dce99-777c-476f-98c6-81ac62025df2", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file