Test

You must test REST APIs, their resources, parameters, and so on before implementing REST calls. API testing requires an application to interact with the REST API. You can also use cURL commands or REST clients to test the REST APIs before you implement them in your application.

Testing with cURL

Use cURL, which is a command-line tool for transferring data using URL syntax, to test REST services. The cURL tool is available in most UNIX, Windows, and Macintosh environments. For details, see Installing the cURL Command-Line Tool on Windows.

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

Option Description

-user

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

-output

<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

Use GET to retrieve all incident records

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

Use PATCH to update a contact

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

Use POST to create an incident

curl -u service_cloud_user: -X POST -H "OSvC-CREST-Application-Context:Create Incident" -H "Content-Type:application/json" -d "{\"primaryContact\":{\"id\":2},\"subject\":\"Test Incident\"}" https://mysite.example.com/services/rest/connect/v1.4/incidents

Testing with REST Clients

You can use third-party browser extensions or add-ons such as the Advanced REST Client and Postman to test Oracle Service Cloud REST APIs.

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

Operation

Response/Payload

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 opportunity.

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

Request URI:

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

Request body:

{
"name": "PCS- 100 laptops"
}
{
  "id": 3,
  "lookupName": "PCS- 100 laptops",
  "createdTime": "2016-03-14T17:39:07.000Z",
  "updatedTime": "2016-03-14T17:39:07.000Z",
  "accountHierarchy": {
    "links": [
      {
        "rel": "self",
        "href": "https://mysite.example.com/services/rest/connect/v1.4/opportunities/3/accountHierarchy"
      }
    ]
  }
...

Update a holiday.

Use the PATCH operation with the following request URI and request body to partially update a holiday object:

Request URI:

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

Request body:

{
"name": "Labour Day"
}
{
  "id": 5,
  "lookupName": "Labour Day",
  "adminVisibleInterfaces": {
    "links": [
      {
        "rel": "self",
        "href": "https://mysite.example.com/services/rest/connect/v1.4/holidays/5/adminVisibleInterfaces"
      }
    ]
  },
  "displayOrder": 3,
  "holidayDate": "2016-09-05",
  "name": "Labour Day",
...