Forum Discussion
ETL API Loop Code Example Help (POC)
- 1 month ago
import requests
import json
import time
from datetime import datetime
# Configuration (POC only - do NOT hardcode in production)
BASE_URL = "https://api.company.com" # paste url hereTOKEN = "PASTE_YOUR_BEARER_TOKEN_HERE" # paste bearer token here
HEADERS = {
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json"
}
# for 10 client
clients = [
"Client01",
"Client02",
"Client03",
"Client04",
"Client05",
"Client06",
"Client07",
"Client08",
"Client09",
"Client10"
]# define Source
sources = [
"orders",
"customers",
"products",
"inventory",
"payments",
"employees",
"pricing",
"transactions",
"suppliers",
"shipments"
]# ----------------------------------------------------
# Simple logging list
# ----------------------------------------------------log = []
# ----------------------------------------------------
# Main Loop
# ----------------------------------------------------for client in clients:
print(f"\nProcessing {client}")
for source in sources:
url = f"{BASE_URL}/{source}?client={client}"
#starting timestart = time.time()
try:
response = requests.get(
url,
headers=HEADERS,
timeout=300
)duration = round(time.time() - start, 2)
response.raise_for_status()
# Save raw JSON
with open(f"{client}_{source}.json", "w") as f:
json.dump(response.json(), f, indent=2)
# logging Pipeline thing
log.append({
"Client": client,
"Source": source,
"Status": "Success",
"DurationSeconds": duration,
"Timestamp": str(datetime.now())
})print(f"✔ {source} completed in {duration}s")
except Exception as ex:
duration = round(time.time() - start, 2)
log.append({
"Client": client,
"Source": source,
"Status": "Failed",
"DurationSeconds": duration,
"Error": str(ex),
"Timestamp": str(datetime.now())
})print(f"✖ {source} failed - {ex}")
# Continue with next source
continue# ----------------------------------------------------
# Save execution log
# ----------------------------------------------------with open("ExecutionLog.json", "w") as f:
json.dump(log, f, indent=2)print("\nPOC Complete")
this is sample code according your requirement you modify that. in this you get time impact for complete procees from calling api to store data into fileif my approch is helpfull for you then mark as solution
if you have still confusion then you can contact me
Thank you
Hi icassiem
Following up to confirm if the earlier responses addressed your query. If not, please share your questions and we’ll assist further.
Yash8160 , v-aatheeque Apologies, i am quickly wrapping up the MVP report and will start with the POC soon. Can i take the script of Yash8160 i place it in the Databricks personal to execute and changke what is needed like the api, credentials etc? I have received the stage api i just need to test in postman first