Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# Salesforce API credentials (you should store these securely)
|
8 |
+
SALESFORCE_INSTANCE_URL = 'https://vedavathi3-dev-ed.develop.my.salesforce.com'
|
9 |
+
SALESFORCE_ACCESS_TOKEN = 'jqe4His8AcuFJucZz5NBHfGU'
|
10 |
+
|
11 |
+
# Salesforce 'Pole' object API endpoint
|
12 |
+
POLE_API_ENDPOINT = f'{SALESFORCE_INSTANCE_URL}/services/data/v52.0/sobjects/Pole__c/'
|
13 |
+
|
14 |
+
@app.route('/create_pole', methods=['POST'])
|
15 |
+
def create_pole():
|
16 |
+
pole_data = request.json
|
17 |
+
|
18 |
+
# Prepare the payload for Salesforce
|
19 |
+
payload = {
|
20 |
+
"Name": pole_data['name'],
|
21 |
+
"Power_Required__c": pole_data['powerRequired'],
|
22 |
+
"RFID_Tag__c": pole_data['rfidTag'],
|
23 |
+
"Location_Latitude__c": pole_data['locationLat'],
|
24 |
+
"Location_Longitude__c": pole_data['locationLong']
|
25 |
+
}
|
26 |
+
|
27 |
+
# Send the request to Salesforce to create a new Pole record
|
28 |
+
response = requests.post(
|
29 |
+
POLE_API_ENDPOINT,
|
30 |
+
headers={
|
31 |
+
'Authorization': f'Bearer {SALESFORCE_ACCESS_TOKEN}',
|
32 |
+
'Content-Type': 'application/json'
|
33 |
+
},
|
34 |
+
data=json.dumps(payload)
|
35 |
+
)
|
36 |
+
|
37 |
+
if response.status_code == 201:
|
38 |
+
return jsonify({"message": "Pole record created successfully"}), 201
|
39 |
+
else:
|
40 |
+
return jsonify({"error": "Failed to create pole record", "details": response.json()}), 500
|
41 |
+
|
42 |
+
if __name__ == '__main__':
|
43 |
+
app.run(debug=True)
|