Axios Not Returning JSON

Hey MongoDB friends,

I’m working on an Atlas function where I make a get request using Axios, and the returned data is not what I’m expecting. The code runs fine and returns the expected JSON locally, however, in Mongo it returns in an unknown format:

const axios = require('axios').default;

exports = async function (username) {
    const BASE_URL = context.environment.values.BASE_URL;

    try {
        const full_url = BASE_URL.replace('{username}', encodeURIComponent(username));
        console.log('Full URL:', full_url);

        for (let retry = 0; retry < 1; retry++) {
            console.log(`Attempt ${retry + 1}`);
            const headers = {
// headers here, removed for security

            console.log("*********FULL_URL:", full_url);
            console.log('Request headers:', JSON.stringify(headers));
            const response = await axios.get(full_url, { headers });
            console.log('Response status:', response.status);
            console.log('Response data:',;
    } catch (error) {
        console.error('Final error:', error);
        return { error: error.message };

This returns:

Response status: 200
Response data: ��V�o�6�WX���/َm��<��[�u�a����N�T���>��%K�lw(�b��0�#�>��a�y3/�N<���*\�Ƥz�� etc......

Anyone have any ideas what might be going on?

This can be closed. I just updated Axios to the latest version. I saw some people that suggested an older version because “newer versions of Axios don’t work in Mongo”, but that’s false or not true anymore.