[SalesForce] SOQL Query Opportunities REST API

First time post here and I'm quite new to the SF ecosystem as well. I'm currently trying to figure out how to properly form queries using SOQL + REST.

Ideally what I am trying to do is query an endpoint like:

services/data/v37.0/?q=SELECT+Opportunities+WHERE+id+LIKE+'ID_NUMBER'

I've read a few different ways to go about doing this, but I'm not sure if creating a query like this is the best way, or it using the query() endpoint is better.

I'm just looking for some guidance on pulling back open opportunities at this point.

Best Answer

Your query does not use valid syntax. There are a few things you need to fix:

  • Your SELECT clause must contain a comma delimited list of fields to return
  • You need a FROM clause that tells the system which object to query
    • The API Name of the object you are trying to query is Opportunity, not Opportunties
  • You cannot use a LIKE clause on Id values. If you have an exact value to filter on, use =
  • If you want to pull back all open Opportunity records, filter on the IsClosed field.

If you're going to use the REST API, note also from Execute a SOQL Query in the Force.com REST API Developer Guide that you have a couple more issues you need to fix in your endpoint path:

  • You must add /query/ after the version (i.e. /v37.0/query/?q=...)
  • You must start with a leading slash (i.e. /services/...)

Putting it all together, you are looking for something along these lines:

/services/data/v37.0/query/?q=SELECT+Name+FROM+Opportunity+WHERE+IsClosed=false
Related Topic