When attempting to create a custom object using Python requests, an "INVALID_FIELD" error was encountered.
import requests
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
url = f'{base_url}/services/data/v52.0/tooling/sobjects/CustomObject'
payload = {
'FullName': 'MyCustomObject__c',
'Label': 'My Custom Object',
'PluralLabel': 'My Custom Objects',
'DeploymentStatus': 'Deployed',
'SharingModel': 'ReadWrite',
'Fields': [
{
'FullName': 'Name__c',
'Label': 'Name',
'Type': 'Text',
'Length': 200,
'Required': True,
'Description': 'The name of the record'
},
{
'FullName': 'Age__c',
'Label': 'Age',
'Type': 'Text',
'Length': 50,
'Required': True,
'Description': 'The Age of the record'
}
]
}
response = requests.post(url, json=json.dumps(payload), headers=headers)
if response.status_code == 201:
print('Custom object created successfully.')
else:
print('Failed to create custom object.')
print('Response:', response.json())
I want to ensure that the payload and URL I have for creating a custom object in Salesforce are valid.