Quick Start

You can use the REST APIs for Service Usage Metrics in Oracle B2C Service to generate both session and non-session reports by specifying filters and get the report data in either JSON or CSV format.

Step 1: Consider Before You Start

Review the basics. If you're new to REST APIs, make sure you understand the basics of REST and JSON, and scan our list of important terms.

Review Roles and Privileges. You must have the necessary security roles and privileges to use the GET, POST, PATCH, and DELETE methods on your parent and child resources.

Review opt-in requirements. Some resources or their attributes may be associated with features that require opt-in before you can use them. You must make sure that you enable opt-in features before you start.

Choose a REST client. REST APIs connect software programs over the HTTP protocol. You need a software client to send the HTTP requests. In our examples, we use cURL. But, cURL isn't the only tool you can use. To help you choose one, see Work with your REST Client.

You can integrate with the REST APIs for Service Usage Metrics in Oracle B2C Service through custom client applications developed using languages such as Java, JavaScript, Ruby, and so on.

Do NOT use the swagger.json available on Oracle Help Center to develop integration code for the REST APIs for Service Usage Metrics in Oracle B2C Service. This swagger.json is a sample created solely for documentation purposes and doesn't fully express the capabilities of the REST APIs for Service Usage Metrics in Oracle B2C Service.

Step 2: Get Your Oracle B2C Service Account Info

To make a REST HTTP request, you need to gather a few bits of information:

  • REST Server URL. Typically, this is the URL of your Oracle B2C Service server. For example:
    https://mysite.example.com
  • User name and password. An Oracle B2C Service user with permissions to access the REST resources you're using.

You can find the REST Server URL, user name, and password in the welcome email sent to your Oracle B2C Service administrator.

Step 3: Configure Your Client

With the information gathered so far, you're ready to configure your client to send a REST HTTP request.

  1. Construct the request URL. The URL consists of the server name and the resource path:
    https://<server>/<resource-path>

    The <server> is the REST Server URL from Step 2, as in:

    https://mysite.example.com

    The <resource-path> is the relative path or endpoint to the resource you're working with. You can pick any endpoint in All REST Endpoints. For example, we're interested in getting the metric data:

    /AgentWeb/api/analyticsmanager/serviceUsageMetrics/metricData/{metricsName}

    where {metricsName} is the metric for which you're generating the report.

    Combine the REST Server URL and, in this example, the resource path and your request URL is complete. For more information, see URL Path.

    https://mysite.example.com/AgentWeb/api/analyticsmanager/serviceUsageMetrics/metricData/{metricsName}
  2. Set the custom headers. You must include the following customer header in your requests:
    • USERSESSION: The session authentication token for the header. See Step 4 for details.

    Include the custom header using the -H command as follows:

    -H "USERSESSION: feihg98GnT7i"
  3. Set the parameters. Replace {metricsName} with a valid metric name.

    Specify filter values as path parameters based on the metric type. In this example, we are generating a report for the NamedUsers metric with a start date of August 20, 2024.

    https://mysite.example.com/AgentWeb/api/analyticsmanager/serviceUsageMetrics/metricData/NamedUsers?startDate=2024-08-20T00%3A00%3A00&format=JSON

If you're not familiar with any of the syntax used in the example, check out Work with your REST Client.

Step 4: Authenticate and Authorize

Now that you've configured the client with a complete request URL, it's time to authenticate and authorize yourself. Authentication proves that your credentials are genuine, and authorization allows you to apply your access privileges.

Authentication

To make sure data access over a network is secure, you use the following authentication process:

  1. Generate a JSON web token (JWT token) using the OAuth authentication method.

    For more information on how to generate a JWT token, see Use JSON Web Token for Authorization.

  2. Using the JWT token, obtain a session authentication token.

    For more information on obtaining a session authentication token, see Get an authentication token.

  3. Access the REST APIs by passing the session authentication token in the USERSESSION header in your requests.

    For more information on accessing the REST API to generate a report, see Get a report.

Let's look at an example for obtaining a session authentication token for sites 24C and higher. To obtain a session authentication token, you must submit the JWT Token and the REST server interface URL for your Oracle B2C Service site, using the following cURL command:

curl -X POST "https://mysite.example.com/AgentWeb/api/analyticsmanager/serviceUsageMetrics/authentication/authToken" -H "accept: application/json" -H "Authorization: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbi" -H "interfaceUrl: https://mysite.example.com/cgi-bin/mysite.cfg"

When passing the JWT token in Postman, the Authorization Type must be Bearer Token, as shown in this screenshot:

This is how you pass a bearer token in Postman.

If your request is successful, you receive a session authentication token in the response with a body similar to the following example. The session authentication token in the following example has been abbreviated for readability.

{
    "description": "Authorization token",
    "token": "feihg98GnT7i"
}

You can now access the REST APIs by passing the session authentication token in the USERSESSION header in your requests.

Step 5: Send an HTTP Request

You're almost done. Now that your authentication and authorization are set, you're ready to send a test HTTP request. Continuing with our example, we want to get the metric data report. You can do this using the following command in cURL:

curl -X GET "https://mysite.example.com/AgentWeb/api/analyticsmanager/serviceUsageMetrics/metricData/NamedUsers?startDate=2024-08-20T00%3A00%3A00&format=JSON" -H "USERSESSION: feihg98GnT7i" -H "Content-Type: application/json"

This is how the request looks in Postman:

This is how a request looks in Postman.

If your request for the report for named users is successful, you receive a response with a body similar to the following abbreviated example. If your request fails, and you're using cURL, review the response comments, adjust your request, and then try again. If you're using other clients, review the failure Status Codes, and then try again.

[{"metricPeriod":"08/20/2024 11:00 PM","metricCount":"4096"},
{"metricPeriod":"08/21/2024 11:02 PM","metricCount":"4096"},
{"metricPeriod":"08/22/2024 11:02 PM","metricCount":"4096"},
{"metricPeriod":"08/23/2024 11:02 PM","metricCount":"4096"},
{"metricPeriod":"08/24/2024 11:02 PM","metricCount":"4096"},
{"metricPeriod":"08/25/2024 11:01 PM","metricCount":"4096"},
{"metricPeriod":"08/26/2024 11:01 PM","metricCount":"4096"}]

Congratulations! Now you're ready to do more with your REST APIs.

  • You can use the APIs to write customizations using a scheduling tool of your choice to schedule reports and receive them regularly, in a channel of your choice, for easier tracking of the usage.
  • Go through the Work with your REST Client section.
  • Join the Oracle Developer Community, where you can share tips and advice with others.