I am currently working on a project to create a document from an SMS.
Our SMS gateway provider will forward all inbound SMS to the URL we provided, https://<sitename>/api/resource/<doctype>.
My problem is that some parameters name (keys) used by our provider in sending the data are not all in lowercase letters resulting to data not being saved to the document. https://<sitename>/api/resource/<doctype>?segmentCount=value&segmentNumber=value&referenceNumber=value&...
Since Python is a case sensitive programming language, is there a way to convert all the keys to lowercase letters?
# Assuming you receive the SMS data in a dictionary called 'sms_data'
sms_data = {
'segmentCount': 'value',
'segmentNumber': 'value',
'referenceNumber': 'value',
# ... other keys and values
}
# Convert the keys to lowercase
lowercase_sms_data = {}
for key, value in sms_data.items():
lowercase_key = key.lower()
lowercase_data[lowercase_sms_data] = value
# Make a request to the ERPNext API using the lowercase keys
url = 'https://<sitename>/api/resource/<doctype>'
response = requests.post(url, json=lowercase_sms_data)
# Check the response or handle any errors
if response.status_code == 200:
print('Document created successfully!')
else:
print('Error creating the document:', response.text)