function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alex OlingerAlex Olinger 

Creating an opportunity using Rest API

Using the following call and JSON data I have been trying to Create a new opportunity attached to an account. Headers/Call are correct as I've been able to create Leads/Accounts. Something with the JSON is wrong but i'm not sure what it is. 

/services/data/v53.0/sobjects/Opportunity

data={
'Name': "Test opportunity",
'Accountid': "XXXXXXXXXXXXX",
'closedate': "1/12/2021",
'stagename':"Needs Analysis",
'Probability': "10"
}
Best Answer chosen by Alex Olinger
Abdul KhatriAbdul Khatri
Use the following, made the following changes
  • Changes single quote to double quote
  • Change the date format
  • Give the real AccountId.
 
data = {
"Name": "Test opportunity",
"Accountid": "XXXXXXXXXXXXX",
"closedate": "2021-13-12",
"stagename":"Needs Analysis",
"Probability": "10"
}

 

All Answers

Abdul KhatriAbdul Khatri
Use the following, made the following changes
  • Changes single quote to double quote
  • Change the date format
  • Give the real AccountId.
 
data = {
"Name": "Test opportunity",
"Accountid": "XXXXXXXXXXXXX",
"closedate": "2021-13-12",
"stagename":"Needs Analysis",
"Probability": "10"
}

 
This was selected as the best answer
Alex OlingerAlex Olinger
@Abdul Khatri
That worked, I believe the issue I was having was the format of the Date. 
Another question, is there anyway to call the account with the actual name? For my script storing the IDs will be kind of a nightmare. 
swapna bhaskaruniswapna bhaskaruni
@Alex Olinger and @Abdul Khatri, how do i know the names of the other fields allowed.... like Name, Accountid, closedate, stagename , what are all the possible fields allowed. is there a documentation for this service?