Search code examples
javascriptfetchauthorizationtypeerrorbasic-authentication

TypeError: Failed to fetch + net::ERR_NAME_NOT_RESOLVED when POSTing to API


So I'm trying to POST to an API endpoint some JSON data. I've setup the following fetch request but receive the error below which I've attached a screenshot of.

Been having a lot of trouble with this and if anyone has some input please share!

fetch(url, {
                headers: {
                    'Authorization': 'Basic ' + btoa(`${user}:${org}:${api_key}`),
                    'Content-Type': 'application/json; charset=UTF-8',
                    'Access-Control-Allow-Headers': '*'
                },
                method: 'post',
                mode: 'cors',
                credentials: 'include',
                body: formObject,
            }).then(function (res){
                return res.text();
            }).then(function (text){
                console.log(text);
            }).catch(function (error){
                console.log(error);
            })

Errors in console


Solution

  • Closing this as it was discovered the server was hosted in the US and the dev team is in UK. AWS was stopping requests from overseas meaning we were receiving these errors and communication was cut early basically.