Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,19 +85,40 @@ def dashboard():
|
|
| 85 |
|
| 86 |
@app.route('/submit', methods=['POST'])
|
| 87 |
def submit():
|
| 88 |
-
data = request.json
|
| 89 |
-
name = data.get('name')
|
| 90 |
-
email = data.get('email')
|
| 91 |
-
phone_number = data.get('phone_number')
|
| 92 |
-
|
| 93 |
-
if not name or not email or not phone_number:
|
| 94 |
-
return jsonify({'error': 'Missing required fields'}), 400
|
| 95 |
-
|
| 96 |
try:
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
-
return jsonify({
|
| 101 |
|
| 102 |
@app.route("/menu", methods=["GET"])
|
| 103 |
def menu_page():
|
|
|
|
| 85 |
|
| 86 |
@app.route('/submit', methods=['POST'])
|
| 87 |
def submit():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
try:
|
| 89 |
+
data = request.json
|
| 90 |
+
name = data.get("name")
|
| 91 |
+
email = data.get("email")
|
| 92 |
+
phone = data.get("phone")
|
| 93 |
+
|
| 94 |
+
if not name or not email or not phone:
|
| 95 |
+
return jsonify({"success": False, "message": "Missing required fields"}), 400
|
| 96 |
+
|
| 97 |
+
# Prepare data for Salesforce
|
| 98 |
+
salesforce_data = {
|
| 99 |
+
"Name": name,
|
| 100 |
+
"Email__c": email,
|
| 101 |
+
"Phone__c": phone
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
headers = {
|
| 105 |
+
"Authorization": f"Bearer {SALESFORCE_ACCESS_TOKEN}",
|
| 106 |
+
"Content-Type": "application/json"
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
response = requests.post(
|
| 110 |
+
f"{SALESFORCE_INSTANCE_URL}/services/data/v52.0/sobjects/{SALESFORCE_OBJECT}/",
|
| 111 |
+
headers=headers,
|
| 112 |
+
data=json.dumps(salesforce_data)
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
if response.status_code == 201:
|
| 116 |
+
return jsonify({"success": True, "message": "Data submitted successfully"})
|
| 117 |
+
else:
|
| 118 |
+
return jsonify({"success": False, "message": "Salesforce submission failed", "error": response.text}), 500
|
| 119 |
+
|
| 120 |
except Exception as e:
|
| 121 |
+
return jsonify({"success": False, "message": "Server error", "error": str(e)}), 500
|
| 122 |
|
| 123 |
@app.route("/menu", methods=["GET"])
|
| 124 |
def menu_page():
|