1

I am trying to get all won opportunities that are new business only for example.

r = requests.get('{}/services/data/v41.0/query'.format(instance_url),params = {'q':'SELECT Name, Type from Opportunity where IsWon=true and CloseDate={0} and type!={1}'.format(today,'Renewal')}, headers=header)

Unfortunately, this brings me the error:

[{"message":"\nCloseDate=2017-12-11 and type!=Renewal\n ^\nERROR at Row:1:Column:87\nBind variables only allowed in Apex code","errorCode":"MALFORMED_QUERY"}]

If I leave the type away it works fine, but giving me, all won opportunities even renewals for example.

Does anyone have a solution? Thanks.

1 Answer 1

3

Instead of:

.format(today, 'Renewal')

Use:

.format('today', '\'Renewal\'')

You want your first argument to be a Date Literal, and the second argument to get merged in as a literal string. That way your filters would read:

WHERE CloseDate = today AND Type != 'Renewal'
1
  • Awesome, you are right with the idea. Thank you very much. One small edit. Today is a datetime.date() and therefore the right solution will be: r = requests.get('{}/services/data/v41.0/query'.format(instance_url),params = {'q':'SELECT Name, Type from Opportunity where IsWon=true and CloseDate={0} and type!=\'{1}''.format(today,'Renewal')}, headers=header)
    – 1574ad6
    Commented Dec 11, 2017 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .