Interview.fetch() Oracle B2C Service Cloud REST API

Thanks must go to Oracle Intelligent Advisor guru and web site supporter AH for the idea for this post. This site has written many articles on the relatively new subject of the Interview Fetch capability. Here is a reminder of the basic principle. In the Hub, we can now place a Connection with a new type of Interview Extension. This represents an endpoint of some kind that can be called from an Interview Extension using the new method interview.fetch() of the interview object.

We’ve already seen some examples here on

  1. Send Email with Fetch()
  2. Transcript Generation
  3. Using Promise in Fetch()

But this post is dedicated to another use of the interview.fetch concept. We will experiment using the Interview to query, update, insert or delete data into Oracle B2C Service aka Oracle Service Cloud aka RightNow. The details of the operations can of course be found in the online documentation for B2C Service.

Let’s look at the setup. We need a Connection in the Hub, pointing to a base URI that is common to all of the REST API endpoints. And we will add Basic Authentication details so that our call will actually be possible.

Now we can build our little interview. We are going to first add an entity to represent our clients. And then we can add the buttons to let us edit, insert, delete each one. Of course I’m cutting corners and doing bad things – I’m hard coding HTML id’s and the like. But I’m in a hurry (I have my 43rd Zoom call of the week in 15 minutes). But the idea is to demonstrate the principle of the Interview Connection :

The connection uses the basic root of the REST API version that we intend to use. Depending on the verb that is selected then various things are displayed.

Oracle B2C Service Cloud Example

The different buttons are of course going to call the REST API in different ways. Here is an example from the POST (to create a contact). The body includes the fields to be sent. The call also includes contentType which is required if there is a body. The relative Uri allows us to build on the root URL to create calls potentially to different objects or services.

var opts = {
			connectionName: "CONNECTIONNAME",
			relativeUri: "/contacts",
			method: "POST",
			contentType : "application/json",
			body: {
				"name": {
					"first": theContactFirst,
					"last": theContactLast
		try {

And here is another example with the DELETE version, where the Id is the only item needed, with no body when calling Oracle B2C Service Cloud:

var opts = {
			connectionName: "YOURCONNECTION",
			relativeUri: "/contacts/" + theContactId,
			method: "DELETE"
		try {

Of course the various variables in these two examples are the contents of the inputs on the Screen. So we can now experiment with the different items and view the responses. It demonstrates the usefulness both of the Oracle B2C Service (Oracle Service Cloud) REST API and the interview.fetch() capability of the Oracle Intelligent Advisor Hub / JavaScript API.

If you wanted to, you could go even further and use a form in the Interview to collect the username and password and send it in to the Connection for authentication purposes. Set up the connection as normal only without the Basic Authentication details.

		var headers = {
			'Authorization': 'Basic ' + btoa(unescape(encodeURIComponent(username + ':' + password)))
		var theContactId = document.getElementById("opmCtl3").value;

		var opts = {
			connectionName: "RN_JS_CON2",
			relativeUri: "/contacts/" + theContactId,
			headers: headers,
			method: "GET"
		try {

Be aware that this comes with it’s own series of risks of course, since Basic Authentication in the browser is not the most secure approach. It would look like this, in Oracle Intelligent Advisor.

If you want the Zip Archive, just leave a note in the comments. Here is a demonstration of the different methods.


Author: Richard Napier

Richard Napier joined Siebel Systems in 1999 and took up the role of managing the nascent Siebel University in Southern Europe. He subsequently was Director of Business Development and Education for InFact Group (now part of Business & Decisions) for 8 years. He now runs Intelligent Advisor IT Consulting OÜ. Owner of, he also is Co-Founder of the Siebel Hub.

5 thoughts on “Interview.fetch() Oracle B2C Service Cloud REST API

  1. Hey Rich,

    Thanks for sharing this info. I am able to complete the Basic authentication but I am wondering if it also works with Bearer token ?
    I tried a lot to make REST API call with Bearer token. Have you ever tried this?
    My requirement is to fetch data from external systems using REST APIs. for that first I need to make API call to get oAUTH access token and then call another API with this token as Bearer token and get the data.

    I stuck with this and no luck. In the failed response I see the type as Basic though I passed it as Bearer in my Header. Any help in this. Thanks Rich !

    body: (…)
    bodyUsed: false
    ok: false
    redirected: false
    status: 401
    statusText: “Unauthorized”
    type: “basic”

    1. I’m guessing that you have been successful in your first call, which has allowed you to obtain the token through, for example, OAuth. Now you need to make further calls and provide the token to be able to make them. So the output of the initial call needs to be captured and the token_type and access_token needs to be passed in the second call. At least that is what I would do if I was using the standard JS fetch(). I’ll look into this in more detail after I return to the office on Monday.

      Call 1:
      fetch(‘https://XXXX/oauth2/token’, {
      method: ‘POST’,
      body: ‘grant_type=client_credentials&client_id=’ + key + ‘&client_secret=’ + secret
      }).then(function (resp) {

      // Return the response as JSON
      return resp.json();

      }).then(function (data) {

      // Log the API data
      console.log(‘token’, data);

      Call 2 :
      // This one uses the token we received for authentication
      fetch(‘https://YYYY’, {
      headers: {
      ‘Authorization’: data.token_type + ‘ ‘ + data.access_token

      }).then(function (resp) {

      // Return the API response as JSON
      return resp.json();

      }).then(function (data) {

      // Log the output data

      }).catch(function (err) {

      // Log any errors
      console.log(‘something went wrong’, err);


  2. Hey Rich,

    Thanks for your help here. the issue got resolved. The ability to override and set the Authorization HTTP header for Interview Extension connection requests was added in the 21B. I upgraded my test instance to 21B and the issue got resolved.

    One more question..

    I am stuck with adding data to Entity through custom extension. My requirement is in global, I have 5 attributes and if I entered value in any attribute, I need to make REST API call and pre-populate the data into Entity. I have no clue how to do that. Do you have any examples where you store the data to Entity?


  3. Hi Narenda. Good to hear. In respect of your second question, If you look into the code examples on this site, then focus on the entity container or entity collect – they should get you in the right direction. You could also look at the Excel data load example on this site as well (Importing Data into an Interview : Excel Example). If you are still struggling, come back here and give a little more information about what you want to achieve and we can use it as an example for an article here. Have a great weekend!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Logo by Southpaw Projects LLC