kenny229
kenny229

Reputation: 177

Delete request api showing error in console when trying to delete an array of id's

Im trying to delete an array of id's by implementing a handler that takes a query parameter. I previously implemented a delete api function that takes one id and deletes it. However, now I have a new endpoint that I created that will clear the whole array. The new endpoint is:

The id's in the endpoint above are just dummy ones to show you how it is supposed to take the id's.

The configIds are passed as query parameters,and the response would be something like this:

So what I did was add the new endpoint to the existing delete api function that currently takes one configId. So:

async function deleteConfig(configId) {
  const options = {
    method: 'DELETE',
    headers: {
      'content-type': 'application/json'
    },
    url: configId.includes(',') ? `/api/v1/algo/configs?configIds=${configId}` : `${ALGOS_API_ROOT}/configs/${configId}`
  };
  return axios(options);

However, I am getting error here:

api/v1/private/api/v1/algo/configs?configIds=41,40,38,23,22 404 (Not Found)

As you can see, the id's are being passed in. But theres an error. Any help would be appreciated. Thanks!

Upvotes: 1

Views: 515

Answers (1)

Robinson De La Cruz
Robinson De La Cruz

Reputation: 156

Send the array of id's in the body of the request.

async function deleteConfig(configId) {
  const options = {
    method: 'DELETE',
    headers: {
      'content-type': 'application/json'
    },
    url: `${ALGOS_API_ROOT}/configs`,
    data: {
      ids: [1, 2, 3]
    }
  };
  return axios(options);
}

Upvotes: 1

Related Questions