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
Adam D DixonAdam D Dixon 

Receiving MALFORMED_QUERY when performing a SELECT query through REST API

While making an authenticated GET call to the REST Query API, I am receiving the following:

[
  {
    "message": "\nSELECT+name+from+Account\n     ^\nERROR at Row:1:Column:6\nunexpected token: '+'",
    "errorCode": "MALFORMED_QUERY"
  }
]

https://{customerName}.my.salesforce.com/services/data/v44.0/query/?q=SELECT+name+from+Account

It's worth noting that the above url is sourced directly from the REST API Developer Guide and that when I execute an authenticated GET request against the REST Describe API endpoint, the description comes back correctly (https://{customerName}.my.salesforce.com/services/data/v33.0/sobjects/Account/describe)

It seems as if this is the only customer that we are experiencing this with.

I'd love any assistance or direction to seek more information.

Thanks in advance!

Best Answer chosen by Adam D Dixon
Sergey Chepurnenko 8Sergey Chepurnenko 8
Hi Adam,

Have you tried to use %20 instead of + in the query?
 

All Answers

GauravGargGauravGarg
Hi Adam,

I just give a try in Workbench using the below query and it worked. Please check your workbench whether it is giving results or not. 
/services/data/v44.0/query/?q=SELECT+name+from+Account+LIMIT+10

Thanks,
Gaurav​​​​​​​
Adam D DixonAdam D Dixon

Gaurav,

Thank you so much for your response.

Unfortunately, the only authentication into the org is the Bearer token (we write API Integrations). We do not have a user login into the org. I did, however, use workbench to access my own org and successfully executed the query. I then copied the exact query into Insomnia with the Bearer token and go tthe MALFORMED_QUERY error code. 

This is what I know so far:

  • Authentication using the Bearer token succeeds (as proven by a successful `describe` call)
  • Other calls succeed (`services/data/v33.0/sobjects/Account/describe`, for example)
  • The same `SELECT` call succeeds on different orgs, but not for this customer
This is what I'm suspecting:
  • Some kind of permissions on the org in question, though I don't know of any that affect SELECT and not DESCRIBE
  • Custom (My) Domain impacts SELECT REST queries, though I've not experienced this before
I'm at a loss for what could be causing this scenario.
Sergey Chepurnenko 8Sergey Chepurnenko 8
Hi Adam,

Have you tried to use %20 instead of + in the query?
 
This was selected as the best answer
Adam D DixonAdam D Dixon
Thanks, Sergey! 

This has solved the issue. When using Insomnia, passing the `+` character through the query in the URL is not supported. Instead, `%20` (space character) can be used to separate parts of the query.

Marking this as resolved.