0

After I run this in the
curl -H "Authorization: MySecretAPI" \ "https://api.pexels.com/v1/search?query=people"
How do I use this in my JSON project in this format

$.getJSON(URL, function (data) {... What should I put for URL, what is the endpoint

  • What does a curl command have to do with ajax? – Taplar Oct 09 '20 at 22:34
  • `https://api.pexels.com/v1/search?query=people` is your endpoint – Taplar Oct 09 '20 at 22:34
  • "error": "Authorization field missing" –  Oct 09 '20 at 22:36
  • So you have to set the header on the ajax request. Ref: https://api.jquery.com/jQuery.ajax/ search for the headers property. You may can also give them on the `getJSON` method, otherwise you will have to revert to the `ajax` method. – Taplar Oct 09 '20 at 22:36
  • how do I add a header –  Oct 09 '20 at 22:41
  • Does this answer your question? [Access Control Request Headers, is added to header in AJAX request with jQuery](https://stackoverflow.com/questions/10093053/access-control-request-headers-is-added-to-header-in-ajax-request-with-jquery) – Taplar Oct 09 '20 at 22:42
  • I just want an endpoint to use. I can look it up and I get a response –  Oct 09 '20 at 22:44

1 Answers1

0

You need to add the authentication header.

try that

$.ajax({
  url : 'https://api.pexels.com/v1/search?query=people',
  dataType: 'json',
  headers: {'Authorization': 'MySecretAPI'},
  success : function(data) {
     console.log(data);
  }
});