Issue encountered while fetching authentication token from the indeed API

I've been trying to obtain an access token from the Indeed API developers. You can find more information about it here:

After creating a fetch request like this:

fetch(`https://apis.indeed.com/oauth/v2/tokens`, {
        method: 'POST',
        mode: 'no-cors',
        headers: {
            'Content-Type' : 'application/x-www-form-urlencoded',
            'Accept':'application/json'
        },
        body: JSON.stringify({client_id:'10efaf31aee65fb0b3dfe149c1e7c902c6c909bd02b1bec27c0a1ba1ae600bd4',client_secret:'Mtabdk9KbUulH9WQSvK5dvm3FTDWRflWJXjpcHiqNn4KozUBXRfBMA02MnTl01uK',grant_type:'client_credentials', scope:'employer_access'})
    })
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.log(error);
    })

However, I keep getting a 400 BadRequest response that looks like this:

Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}

https://i.sstatic.net/0bFUL.png

The API seems to be working fine when tested with Postman. Is there something wrong with my fetch request?

Answer №1

To successfully authenticate, follow these steps:

var myAuth = new Auth();
myAuth.append("Authorization", "Bearer your_access_token");

var dataBody = new Body();
dataBody.append("user", "john.doe@example.com");
dataBody.append("password", "securePassword123");

var requestConfig = {
method: 'POST',
authHeaders: myAuth,
body: dataBody,
redirect: 'follow'
};

fetch("https://example-api.com/authenticate?", requestConfig)
  .then(response => response.json())
  .then(result => console.log(result))
  .catch(error => console.log('Error occurred:', error));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switching videos upon clicking buttons

Hey there! I've got an interesting challenge for you. I have four mp4 videos featuring a cartoon character performing various emotes. My goal is to create a toggle switch that, when activated, will display the first video (intro) along with three butt ...

What is the best way to establish a default selection in Angular?

After retrieving JSON data from the server, it looks something like this: $scope.StateList = {"States": [ { "Id": 1, "Code": "AL", "Name": "Alabama" }, { "Id": 2, "Code": "AK", "Name": "Alask ...

Every time I try to loop through my JSON object using an $.each statement, an error is thrown

When I execute an $.each loop on my json object, I encounter an error 'Uncaught TypeError: Cannot read property 'length' of undefined'. It seems that the issue lies within the $.each loop as commenting it out results in the console.log ...

Combining JSON parameter and multipart/form-data file in a single request using Vue.js

Is there a way to send both JSON parameters and multipart/form-data files in a single request using Vue, similar to how Postman does it? https://i.sstatic.net/CMi3D.png I've been looking into how to submit "multipart/form-data" from VueJs. What I nee ...

What could be the reason for the text color not changing?

Currently, I am utilizing react.js to create a row of three images with a small blurb of text at the top and bottom of each picture. However, I've encountered an issue where changing the color of the text does not reflect on the webpage. Can anyone sh ...

Can anyone provide tips for identifying empty spaces within an HTML document using JavaScript?

Is there a way to detect the spaces between all words on an HTML page using JavaScript? For instance: An example sentence is provided below In this sample, there are visible spaces separating "an" and "example" as well as all subsequent words. Any idea ...

Provide a response for every result produced by the Node-RED function block

Can you please explain how to send multiple messages in Node-RED using function blocks, one for each output? I attempted to follow the documentation but was unsuccessful. msg1 = "1" msg2 = "2"; msg3 = "3"; msg.payload = [msg1, msg2, msg3]; return msg ...

Analyzing and adding Angular JSON information

I'm struggling to understand why the compare function and insert function in my code aren't functioning correctly. I suspect that one reason for this could be that the function is not being called by the button. How can I confirm this? It seems l ...

Is it possible to read a file with a different dynamically generated name each time in Cypress?

Being new to Cypress, I am faced with the challenge of writing a test case to verify the download of a file. Despite researching various resources on similar test cases, they all involve reading a file with a static name. In my scenario, the file is downlo ...

Transferring data to a view

I have a dilemma with handling user selections from a select option list and a jstree object in Django. My goal is to pass these choices to a Django view for processing and obtain a response. I've encountered an issue where the template fails to load, ...

Breaking down an RxJS observable sequence into various outputs

Can a single observable flux be split into multiple other observables? For example, I have a form that users can submit. The submit action is captured by an observable, and a validator is triggered upon submission. submitAction.forEach(validate) However ...

CORS blocking Axios POST request to Heroku causing a Network Error 503

Using the MERN Stack, everything was functioning correctly until modifications were made to the UI (such as relocating code to different components and altering styles). The issue lies with a specific POST request, while other requests that utilize Axio ...

Programmatically loading a URL into an ng-view component

Given the code snippet below, I am looking to dynamically load the URL for the `viewTeam` page into the `ng-view` container upon calling the `showTeam()` function. What would be the best approach to achieve this functionality? <html> <head> ...

The _destroy method of the jQuery widget factory is designed to efficiently

I need help creating a timer widget that can start with a specific number of seconds and be reset at any time by initializing it again with a new set of seconds. I have managed to create the timer and make it count down, but now I am facing an issue. My g ...

sequenced pauses within a sequence of interconnected methods in a class

scenario: There are two javascript classes stored in separate files, each utilizing a different external service and being called within an express.js router. Refer to the "problematic code" section below: route routes.post('/aws', upload.sing ...

Issue with autocomplete feature malfunctioning on both php and javascript

I'm currently working on a simple auto-complete script using Javascript and PHP, but I'm running into some issues. Any help would be greatly appreciated! Here's the HTML code I have: <!doctype html> <html lang="en"> <head> ...

There seems to be an issue with Vue JS slots[name$1].every function as it is

I attempted to implement a custom isEmpty function for the Object prototype as follows: Object.prototype.isEmpty = function() { for (var key in this) { if (this.hasOwnProperty(key)) { return false } } return true } However, when tryin ...

"Having an issue with the jQuery AJAX call where the success function is not operating as expected

I attempted to retrieve information from a database using PHP by making an AJAX call with jQuery. However, I encountered an issue where the $.ajax function was not functioning as expected. There were no error messages displayed, and the console.log('s ...

Vue alert]: The element "options" is not declared in the current instance but is being referenced during the rendering process. Facing problem with Vue JS

Encountering an error while rendering the project. I've thoroughly checked all details but couldn't pinpoint which line is causing the issue. The console displays the following warning: Vue warn]: Property or method "options" is not defined on th ...

Using a javascript parameter in a cshtml file to filter data in a datatable

Here is the model code public class viewCase { public List<string> lstCategory { get; set; } public DataTable dtWrkTsk { get; set; } } This is the controller code string query = "SELECT WorkFlowID,Subject,Category FROM CMSTasksWorkFlow" ob ...