How to correctly execute requests to the server in Polyglot Notebook js cells?

Alexandr 5 Reputation points
2023-05-22T12:53:30.43+00:00

I use a Polyglot Notebook .NET, .ipynb file, and in the javascript code cell I want to make a request to the server using the built-in fetch method/axios, but for some reason I don’t get anything in the console, there are also no errors. What could be the problem?

require(['axios'], function (axios) {
  const url = 'http://myurl.com';
  const token = 'token';
  

  const body = {
    listFields: [],
    searchData: '',
    skip: 0,
    take: 50,
  };

  axios.post(url, body, {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`,
    },
  })
    .then(response => {
      console.log(response.data.dataList);
    })
    .catch(error => {
      console.error(error);
    });
})
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
983 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.