Hi, I'm trying to get data from a 3rd party applic...
# suitescript
j
Hi, I'm trying to get data from a 3rd party application using the http.get but I'm running in to an Unexpected Error message. Here's a snippet of the code I'm using to get data:
Copy code
define(['N/http'], (http) => {
let result = http.get({
    url: 'http://{{base_url}}/ho_api/api/beta/companies',
    headers: {
        name: 'Authorization',
        value: 'Basic YXBpX3VzZXI6WkZ1Q0pmdGJIK045TGgwNdsadasdarZWpnN0pNNGM1UEQ4WEhobDdjcz1='
    }
});
console.log('Result Details', result);
});
** just changed the url and authorization header for privacy purpose. Is there something missing from the script or something wrong about it? thanks :)
b
probably should be using require
and the documentation is usually wrong here
the headers object's keys are header names
and the matching value are header values
so
Copy code
let result = http.get({
  url: "http://{{base_url}}/ho_api/api/beta/companies",
  headers: {
    Authorization:
      "Basic YXBpX3VzZXI6WkZ1Q0pmdGJIK045TGgwNdsadasdarZWpnN0pNNGM1UEQ4WEhobDdjcz1=",
  },
});
1
j
That's it. The script now works after changing the headers object. Thanks!