Jupyter

Edinn API functions can be tested or used using Jupyter. This document will guide you through an example.

1º Install Python and Jupyter (if not already installed):

    • Verify if Python is installed by opening a terminal window and running the command python --version
    • If Python is not installed, download and install it from https://www.python.org/downloads/.
    • Verify if Jupyter is installed by opening a terminal window and running the command jupyter --version
    • If Jupyter is not installed, run the command pip install jupyter to install it.

2º Create a Jupyter file:

    • Open or create any empty repository.
    • Open this folder from the terminal.
    • Run the command  jupyter notebook
    • Create a new file by clicking the "New" button.

3º Copy and paste the following code:

Cell 1: Install Required Libraries

# Install the requests library if not already installed

!pip install  requests

Cell 2: Configuration

# --- Edinn API Configuration ---

EDINN_API_URL = "http://localhost:8080"  # Replace with your edinn API URL

EDINN_COMPANY = "1231231234"  # Replace with your company name

EDINN_USER = "user"  # Replace with your username

EDINN_PASSWORD = "123asd"  # Replace with your password

EDINN_PROCESS = "A0L1"

EDINN_DATEFROM = "202407180000000"

EDINN_DATETO = "202407190000000"

Cell 3: Session Management Functions

import requests

import json

# --- Function to create an edinn session ---

def create_edinn_session():

    url = f"{EDINN_API_URL}/sessions"

    data = {

        "company": EDINN_COMPANY,

        "user": EDINN_USER,

        "password": EDINN_PASSWORD

    }

    try:

        response = requests.post(url, data=data)

        response.raise_for_status()

        session_id = response.json()["data"]

        print(f"Created edinn session: {session_id}")

        return session_id

    except requests.exceptions.RequestException as e:

        print(f"Error creating edinn session: {e}")

        return None


# --- Function to delete an edinn session ---

def delete_edinn_session(session_id):

    url = f"{EDINN_API_URL}/sessions/{session_id}?company={EDINN_COMPANY}"

    try:

        response = requests.delete(url)

        response.raise_for_status()

        print(f"Deleted edinn session: {session_id}")

    except requests.exceptions.RequestException as e:

        print(f"Error deleting edinn session: {e}")


def get_results():

    url = f"{EDINN_API_URL}/results?company={EDINN_COMPANY}&session={session_id}&process={EDINN_PROCESS}&datefrom={EDINN_DATEFROM}&dateto={EDINN_DATETO}"

                       

    try:

        response = requests.get(url)

        response.raise_for_status()  # Check for HTTP errors

        data = response.json()  # Parse the JSON response

        print(f"Data from edinn:")

        print(json.dumps(data, indent=4))  # Pretty-print the JSON data

    except requests.exceptions.RequestException as e:

        print(f"Error finding data: {e}")

Cell 5: Execution python

# --- Create edinn session ---

session_id = create_edinn_session()

get_results()

delete_edinn_session(session_id)

4º Configure your edinn API credentials:

    • Replace the placeholder values in the Edinn API Configuration section with your actual edinn API URL, company name, username, and password.

5º Run the script:

This script will connect to the edinn API, create a session, retrieve data, and then delete the session. The retrieved data will be printed to the console in a formatted JSON structure.

Copyright © 2023 by EDINN GLOBAL, S.L. All Rights Reserved.