Drop files here
or click to upload
import streamlit as st
import requests
import json
# API Details
API_URL = "https://emea.snaplogic.com/api/1/rest/slsched/feed/ConnectFasterInc/snapLogic4snapLogic/Bootcamp_EMEA_August_2025/CRM_Retrievier_Sally%20Task"
HEADERS = {
"Authorization": "Bearer 12345",
"Content-Type": "application/json"
}
st.set_page_config(page_title="SnapLogic CRM Assistant")
st.title("SnapLogic CRM Assistant")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("What opportunities are currently in negotiation?"):
# Display user message in chat message container
st.chat_message("user").markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# Prepare data for API request
payload = json.dumps([{"Question": prompt}])
try:
# Make the API call
response = requests.post(API_URL, headers=HEADERS, data=payload)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
# Parse the JSON response
response_data = response.json()
# Extract the 'response' field from the first item in the list
if response_data and isinstance(response_data, list) and "response" in response_data[0]:
api_response = response_data[0]["response"]
else:
api_response = "I couldn't get a valid response from the API."
except requests.exceptions.RequestException as e:
api_response = f"An error occurred while calling the API: {e}"
except (json.JSONDecodeError, IndexError, KeyError) as e:
api_response = f"Failed to parse the API response: {e}"
# Display assistant response in chat message container
with st.chat_message("assistant"):
st.markdown(api_response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": api_response})
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?