Python
You can test or use the edinn API functions with Python. This document will guide you through an example.
1º Install Python (if not already installed):
- Check 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/
2º Create a Python file:
- Go to your development environment.
- Create a new Python file with the extension ".py" (e.g., example.py).
3º Copy and paste the following code:
import requests
import json
# --- 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"
# --- 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}")
# --- 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:
- Open a terminal window.
- Navigate to the directory where you saved your Python script.
- Execute the script using the command python nombre_de_app.py (replace your_script_name.py with the actual name of your file).
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.