Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Title of the app
|
| 5 |
+
st.title("Modern Treasury API Integration")
|
| 6 |
+
|
| 7 |
+
# Sidebar for API key input
|
| 8 |
+
st.sidebar.header("API Configuration")
|
| 9 |
+
api_key = st.sidebar.text_input("Enter your Modern Treasury API Key", type="password")
|
| 10 |
+
|
| 11 |
+
# Select the API endpoint the user wants to interact with
|
| 12 |
+
endpoint_choice = st.selectbox("Choose API Endpoint", [
|
| 13 |
+
"Payment Orders",
|
| 14 |
+
"Expected Payments",
|
| 15 |
+
"Returns",
|
| 16 |
+
"Incoming Payment Details",
|
| 17 |
+
"Counterparties",
|
| 18 |
+
"Internal Accounts"
|
| 19 |
+
])
|
| 20 |
+
|
| 21 |
+
# Base URL for Modern Treasury API
|
| 22 |
+
base_url = "https://app.moderntreasury.com/api/"
|
| 23 |
+
|
| 24 |
+
# Define API endpoints
|
| 25 |
+
MODERN_TREASURY_ENDPOINTS = {
|
| 26 |
+
"Payment Orders": "payment_orders",
|
| 27 |
+
"Expected Payments": "expected_payments",
|
| 28 |
+
"Returns": "returns",
|
| 29 |
+
"Incoming Payment Details": "incoming_payment_details",
|
| 30 |
+
"Counterparties": "counterparties",
|
| 31 |
+
"Internal Accounts": "internal_accounts"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# Function to fetch data from the selected Modern Treasury API endpoint
|
| 35 |
+
def fetch_data(api_key, endpoint):
|
| 36 |
+
url = base_url + MODERN_TREASURY_ENDPOINTS[endpoint]
|
| 37 |
+
response = requests.get(url, headers={"Authorization": f"Bearer {api_key}"})
|
| 38 |
+
if response.status_code == 200:
|
| 39 |
+
return response.json()
|
| 40 |
+
else:
|
| 41 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
# Main logic to fetch and display data
|
| 45 |
+
if st.button("Fetch Data"):
|
| 46 |
+
if api_key:
|
| 47 |
+
data = fetch_data(api_key, endpoint_choice)
|
| 48 |
+
if data:
|
| 49 |
+
st.json(data)
|
| 50 |
+
else:
|
| 51 |
+
st.error("Please provide a valid API key.")
|
| 52 |
+
|
| 53 |
+
# Display footer
|
| 54 |
+
st.sidebar.markdown("Powered by Streamlit and Modern Treasury API")
|