Video: Query via the REST API

You can use the REST API to query objects from Oracle B2C Service database. The REST API lets you use syntax similar to the SELECT and WHERE clauses in SQL.

Let's look at these examples to understand the query clauses.

Using the WHERE Clause

You need to add the name of the collection of objects to the base URL that you want to query. The objects name must be plural and in camel case.

Syntax:

https://interface_name/services/rest/connect/version_number/resource_name?q='filter_clause'

Example:

https://mysite.example.com/services/rest/connect/v1.3/contacts?q=address.city='Chicago'

In the above example, the text after separator question mark (?), q=address.city='Chicago', represents WHERE clause. When you execute the query, the set of objects that meet the condition are retrieved from the database. Though the REST API WHERE clause syntax is similar to the SQL WHERE clause, there are some differences between the two clauses.

When you execute the following query, you will get the list of all operators that you can use for this particular resource with examples.

Syntax:

https://interface_name/services/rest/connect/version_number/resource_name/contacts-search-form

The list of operators are common comparison operators including LIKE and IN, and logical operators such as AND, OR, and NOT.

The search parameters that you use to query objects are not case-sensitive.

Example:

https://mysite.example.com/services/rest/connect/v1.3/contacts?q=NAME.FIRST='bOb'

The above query retrieves all the contacts that have their first name as 'bob' and irrespective of whether the first name is upper case, lower case, or mixed case.

Using the SELECT Clause

You should query the B2C Service REST API by adding '/queryResults/' to the end of base URL instead of querying for a particular collection of objects.

Example:

https://mysite.example.com/services/rest/connect/v1.3/queryResults/?query=select name.first,name.last from contacts; 

The query retrieves the first name and last name of all the contacts.