2

I am having trouble acessing the Oxford Dictionary API. I keep getting the error 'Authentication parameters missing'.

I believe I am not properly passing the api ID and key. I have referred to this documentation: https://developer.oxforddictionaries.com/documentation/making-requests-to-the-api https://developer.oxforddictionaries.com/documentation

Here is my code; trust me that the app id and key are the correct strings.

const url = 'https://od-api.oxforddictionaries.com/api/v1/entries/en/swim';

fetch(url, {
  method: 'GET',
  headers: new Headers({
    'app_id': oxford.appId, 'app_key': oxford.appKey
  }),
}).then(function(response) {
  console.log(response);
});
Steven Anderson
  • 455
  • 6
  • 13

2 Answers2

2

If the site looking for Authentication header it may refer to Basic Auth Header, read more here. If that is true, you simply can append your header parameter with this:

var headers = new Headers()

headers.append('Authorization', 'Basic ' + base64.encode(app_id + ":" + app_key));

You may try with or without the encoding.

You may also try this if that does not work

const url = 'https://od-api.oxforddictionaries.com/api/v1/entries/en/swim';

fetch(url, {
 method: 'GET',
 headers: { //HERE IS THE DIFFERENCE
   'app_id': oxford.appId, 'app_key': oxford.appKey
 },
 mode: 'no-cors'
}).then(function(response) {
  console.log(response);
}); 

If that does not work, another way to think of, it may be a CORS issue, you can read it more here

May this helps.

  • Not working. I tried it without the encoding first. `base64` is undefined, so i tried `btoa()` and that encoded it, but authentication didn't work. – Steven Anderson Feb 10 '18 at 05:57
  • did you try my second option? – Septi Rito Tombe Feb 10 '18 at 05:59
  • You mean passing a simple object to the headers property as opposed to a Headers object, right? Yes, I did. No go. – Steven Anderson Feb 10 '18 at 06:01
  • Are you sure when you tried my second option it returns 'Authentication parameters missing' instead of 'Authentication failed'? – Septi Rito Tombe Feb 10 '18 at 06:03
  • Yes, 'Authentication parameters missing' – Steven Anderson Feb 10 '18 at 06:05
  • Returned this, too, if it helps: 'Fetch API cannot load https://od-api.oxforddictionaries.com/api/v1/entries/en/swim. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.' – Steven Anderson Feb 10 '18 at 06:05
  • that is interesting because I tried this on my machine `const url = 'https://od-api.oxforddictionaries.com/api/v1/entries/en/swim'; fetch(url, { method: 'GET', headers: { 'app_id': 123, 'app_key': 123 }, }).then(function(response) { console.log(response); }); ` it returns Authenthication failed – Septi Rito Tombe Feb 10 '18 at 06:06
  • hmm, i just copied and pasted what you have and to me it returns 'Authentication parameters missing'. – Steven Anderson Feb 10 '18 at 06:09
  • you may try to add `mode: 'no-cors'` to your fetch option? – Septi Rito Tombe Feb 10 '18 at 06:10
  • doesn't work. Check this out: https://developer.oxforddictionaries.com/documentation#!/Dictionary_entries/get_entries_source_lang_word_id You can look at the coded in a few different languages. Maybe this helps you. Not me though – Steven Anderson Feb 10 '18 at 06:13
  • Hi, I found out what the problem was. See my answer. Thanks for looking into this with me. – Steven Anderson Feb 10 '18 at 20:52
  • Yup, it is a CORS issue then – Septi Rito Tombe Feb 11 '18 at 01:07
0

I found an answer to my question here. Looks like the API does not support client side application requests. Guess I'll have to create a server.

Steven Anderson
  • 455
  • 6
  • 13