OAuth2 and API Json request not working with jQuery Call

690 Views Asked by At

I'm really new to OAuth2 and I'm trying to integrate an TrustPilot's API with my app, but it requires an API key authorization on every Json request. The problem is, I don't know how to include it in the request. The examples they give are not working, but that's only because the "API" key is not there. I don't know where to put it.

What I'm I doing wrong? Below is the code I'm using to get the request.

    function getbusinessreviews() {

var businessUnitId = ''

    jQuery(document).ready(function($) {

      $.ajax({
      url : "https://api.trustpilot.com/v1/business-units/"+businessUnitId+",
      dataType : "json",

      success : function(parsed_json) {
      var Name = parsed_json['displayName'];
      var TotalReviews = parsed_json['numberOfReviews']['total'];


      x.innerHTML = '<i class="'+Name ' , ' + TotalReviews+'</i>';
      }
      });
    });
       } 

Here's the link to the API documentation:

I don't know what I'm missing.

1

There are 1 best solutions below

1
On BEST ANSWER

You should read the notes about authentication on the Introduction section on their documentation site. It says that you do not need to obtain an OAuth token for most requests, and not this one either.

So if you just pass your API key with you request like this:

https://api.trustpilot.com/v1/business-units/[yourbusinessunitid]?apikey=[yourapikeyhere]

It should work.