Work with your REST Client

Because REST APIs use HTTP methods to send and receive content, you can test REST APIs using any programming language or tool that supports sending and receiving HTTP messages. So, let's first choose a tool for making HTTP requests.

Considerations for Choosing a REST Client

You can choose among many clients that interact with Oracle B2C Service, such as:

  • A standalone client, such as Postman or Advanced REST Client
  • Your connecting application's client
  • The cURL command-line utility

With a client you can:

  • Test the username, password, and request URL for your REST API account.
  • Access the metadata to learn more about REST resources, attributes, and parameters.
  • Use the collected information to construct and send various types of HTTP requests, such as those to create, update, or delete records.

How You Send HTTP Requests Using cURL

In our examples, we use cURL, a popular command-line utility for transferring data using URL syntax, to send requests to REST services. cURL is available in most UNIX, Windows, and Macintosh environments. For details, see Installing the cURL Command-Line Tool on Windows.

The following table describes commonly used cURL options that you can use for REST services.

Option Description

-u

username:password

Specifies the user name and password for server authentication.

-d

Sends the specified data (a JSON request body) to the server. If you begin the data with the at sign (@), it must be followed by the file name to read the data from. For example, -d@example_request_payload.json

-H

Specifies an extra HTTP header in the request. To specify multiple headers, precede each header with the -H option.

Examples:
  • Content-Type: Format of Request Body (for example, with POST)
  • Accept: Format of Response Body
  • X-Auth-Token: Authentication Token

-o

<file>

Writes the output to a file instead of to stdout.

-X

Specifies the request method to use when communicating with the HTTP server. The default method is GET.

The following table shows examples of the GET, PATCH, and POST operations using cURL.

Operation cURL Command Example

Use GET to retrieve all account records

curl -u "username:password" -X GET -H "OSvC-CREST-Application-Context:Retrieve all accounts" https://mysite.example.com/services/rest/connect/v1.4/accounts

Use PATCH to update an account

curl -u "username:password" -X PATCH -H "OSvC-CREST-Application-Context:Update Account" -H "Content-Type:application/json" -d "{\"name\":{\"first\":\"George\"}}" https://mysite.example.com/services/rest/connect/v1.4/accounts/2

Use POST to create an account

curl -u "username:password" -X POST -H "OSvC-CREST-Application-Context:Create Account" -H "Content-Type:application/json" -d "{\"login\": \"guest\",\"name\": {\"first\": \"Guest\",\"last\": \"Account\"},\"profile\": {\"id\": 12},\"staffGroup\": {\"id\": 100303}}" https://mysite.example.com/services/rest/connect/v1.4/accounts

How You Send HTTP Requests Using Clients

You can use standalone clients, third-party browser extensions, or add-ons, such as the Advanced REST Client, to send HTTP requests.

The following table includes examples of the GET, POST, and PATCH operations using a client.

Operation Response/Payload Example

Get an account.

Use GET with the following request URI to retrieve data for an account object:

https://mysite.example.com/services/rest/connect/v1.4/accounts/1
{
  "id": 1,
  "lookupName": "Administrator -",
  "accountHierarchy": {
    "links": [
      {
        "rel": "self",
        "href": "https://mysite.example.com/services/rest/connect/v1.4/accounts/1/accountHierarchy"
      }
    ]
  },
  "attributes": {
    "accountLocked": false,
    "canModifyEmailSignature": false,
    "forcePasswordChange": false,
    "infrequentUser": false,
    "passwordNeverExpires": false,
    "permanentlyDisabled": false,
    "staffAssignmentDisabled": true,
    "viewsReportsDisabled": true,
    "virtualAccount": false
  }
... 

Create an account.

Use POST with the following request URI and request body to create a new account object:

Request URI:

https://mysite.example.com/services/rest/connect/v1.4/accounts

Request body:

{
  "login": "guest",
,
    "last": "Account"
  },
  "name": {
    "first": "Guest"  "profile": {
    "id": 12
  },
 "staffGroup": {
    "id": 100303
  }
}
{
{
  "id": 108,
  "lookupName": "Guest Account",
  "accountHierarchy": {
    "links": [
      {
        "rel": "self",
        "href": "https://mysite.example.com/services/rest/connect/v1.4/accounts/108/accountHierarchy"
      }
    ]
  },
  "attributes": {  
...

Update an account.

Use the PATCH operation with the following request URI and request body to partially update an account object:

Request URI:

https://mysite.example.com/services/rest/connect/v1.4/accounts/108

Request body:

{
"login": "guest2"
}

{
  "id": 108,
  "lookupName": "Guest Account",
 ...
  "login": "guest2",
  "manager": null,
  "name": {
    "first": "Guest",
    "last": "Account"
  },
 ...

With an understanding of how your client works, you can next review Work with Contacts to Reset Passwords, Send Mailings, and Run Marketing Campaigns for a sample that demonstrates how to reset the password of a contact, send a mailing to a contact, and execute a marketing campaign.