TheThingsArchive / api

Generated code for accessing The Things Network v2 API
MIT License
12 stars 8 forks source link

Error 401 (Unauthorized) Access to API Using Javascript #35

Closed amaenhout closed 5 years ago

amaenhout commented 5 years ago

Hi,

I'm trying to connect with the storage api using javascript & JQuery (Ajax) but it is not working.

I tested the api also in in Postman, Python and Curl and all tests were successful, hereby my javascript code:

var settings = {

    "url": "https://bartlett_workshop_environmental.data.thethingsnetwork.org/api/v2/devices",
    "method": "GET",
    "dataType":"jsonp",
    "headers": {
      "Accept": "application/json",
      "Authorization": "key ttn-accountv2 xxxxxxxxxxxxxxx  ",// (changed to account key)
    }
  }

  $.ajax(settings).done(function (response) {
    console.log(response);
  });

Result: image

Could anyone help me out?

Thanks in Advance!

johanstokking commented 5 years ago

We don't support ajax calls directly from the browser.