dschandra's picture
Create app.py
41a51fd verified
raw
history blame
1.41 kB
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)