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