Developers

SDK JS-Client

Introduction

The Benti JS-Client allows you to call an Inbenta API endpoint quickly and easily with javascript.

Note: All examples shown are set in a Production environment.

Setup

Steps to follow:

  1. Integration

    Include the Inbenta Benti SDK script somewhere in your page:

     <script src="https://sdk.inbenta.io/benti/benti-js-client/<version>/benti-js-client.js"></script>
  2. Creation

    Next, create a new client instance. To do so, you will need your API Key (public key) and your domain key. See Finding your API credentials in the Help Center to obtain your credentials.

    The following example shows a creation using a domain key.

      var client = InbentaBentiClient({ domain_key: '<your_domain_key>', api_key: '<your_API_Key>' }).build();
  3. Use client

    
    client.createTicket({
        creator: {
            address:'<email_address>',
            extra:[],
            name:'<name>'
       },       
       message:'<message>'
    }).then(function(result){
        console.log(result);
    });
    

    Important Please keep in mind that Inbenta APIs accept HTTPS requests only. If you need to send API requests using other protocols, the only way to do this is to set up a proxy to convert those protocols to the HTTPS protocol before the requests reach the API.

Example

<!doctype html>
<!doctype html>
  <  lang="en"> 
    <head> 
      <script src="https://sdk.inbenta.io/benti/benti-js-client/<version>/benti-js-client.js"></script> 
  </head> 
  <body> 
    <script type="text/javascript"> 
      var domain_key = '<your_domain_key>'; 
      var api_key = '<your_API_key>'; 
      var client = InbentaBentiClient({ domain_key, api_key }).build(); 

      client.createTicket({ 

        creator: { 
           address:'<email_address>', 
           extra:[], 
           name:'<name>' 
        }, 
        message:'<message>' 

      }).then(function(result) { 
          console.log(result); 
      }); 
    </script> 
  </body>
<html>

Versions

When you set up the SDK for your Inbenta product, you need to specify the version like this:

<script integrity="<hash-type>-<hash>" crossorigin="anonymous" src="https://sdk.inbenta.io/benti/benti-js-client/<version>/benti-js-client.js"></script>

Note: A subresource integrity hash table is available for this client here.

Versions are written in MAJOR.MINOR.PATCH format.

Important:

  • Do NOT cache or store these files, otherwise you will not benefit from bug fixing and minor upgrades.
  • Inbenta strongly recommends that you use a MAJOR.MINOR.PATCH version.

Examples

  • If only MAJOR is set, this script will use the highest available MINOR version. <script integrity="<hash-type>-<hash>" crossorigin="anonymous" src="https://sdk.inbenta.io/benti/benti-js-client/1/benti-js-client.js"></script>
  • If MAJOR.MINOR are set, this script will use the highest available PATCH version. <script integrity="<hash-type>-<hash>" crossorigin="anonymous" src="https://sdk.inbenta.io/benti/benti-js-client/1.2/benti-js-client.js"></script>
  • If you specify the full version, only this exact version will be used. <script integrity="<hash-type>-<hash>" crossorigin="anonymous" src="https://sdk.inbenta.io/benti/benti-js-client/1.2.3/benti-js-client.js"></script>

Client Creation explanation

To create a new SDK instance, you need your API Key and a domain key. Contact your Inbenta representative to receive these credentials.

Methods

All JS Client methods are described here.

Handling Errors

Click here to see a list of API error codes.


client.createUser(data).catch(function (error) { 

    if (error.response) { 
       // The request was made and the server responded with a status code 
       // that falls out of the range of 2xx 
       console.log(error.response.data); 
       console.log(error.response.status); 
       console.log(error.response.headers); 
    } else { 
       // Something happened in setting up the request that triggered an Error 
       console.log('Error', error.message); 
    } 
});