I'm attempting to execute a simple anonymous Apex script via Python with the simple_salesforce library.

from simple_salesforce import Salesforce

sf = Salesforce(instance=scratch_org_instance, session_id=access_token)
result = sf.toolingexecute('executeAnonymous', method='GET',data={"anonymousBody": 'Integer x = 0;'})

Upon executing I'm receiving the following compile error {'line': 1, 'column': 1, 'compiled': False, 'success': False, 'compileProblem': "Unexpected token '<EOF>'.", 'exceptionStackTrace': None, 'exceptionMessage': None}

The Apex provided in the anonymousBody parameter seems correct, so I'm thinking my request might be off.

1 Answer 1


Turns out simple_salesforce nulls out the data parameter in their toolingexecute implementation. I've resolved my problem via the following: result = sf.toolingexecute('executeAnonymous/?anonymousBody=Integer x=0;','GET')

Snippet from their library to illustrate this (see the data parameter):

def toolingexecute(self, action, method='GET', data=None, **kwargs):
        """Makes an HTTP request to an TOOLING REST endpoint
        * action -- The REST endpoint for the request.
        * method -- HTTP method for the request (default GET)
        * data -- A dict of parameters to send in a POST / PUT request
        * kwargs -- Additional kwargs to pass to `requests.request`
        # If data is None, we should send an empty body, not "null", which is
        # None in json.
        json_data = json.dumps(data) if data is not None else None
        result = self._call_salesforce(
            self.tooling_url + action,
            data=json_data, **kwargs
            response_content = result.json()
        # pylint: disable=broad-except
        except Exception:
            response_content = result.text

        return response_content

You must log in to answer this question.

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