DELETE restAPI request returns 204, but entry is not deleted

Hey dear Strapi community ^^

Here’s my code:

  deleteVerificationToken: async (id: number) => {
    const url = `${process.env.STRAPI_URL}/api/verification-tokens/${id}`;

    try {
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${process.env.STRAPI_AUTH_TOKEN}`,
        },
      });

      if (!response.ok) {
        const errorData = await response.json();
        throw new Error(errorData.message || "Response was not ok.");
      }
      console.log("Token successfully deleted!")
    }
    catch (error) {
      console.log(error);
    }
  },

As I say in the title, when the above runs I get the following in my strapi terminal:

http: DELETE /api/verification-tokens/8 (3 ms) 204

But the entry still exists in my strapi dashboard. What am I missing?

This topic has been created from a Discord post (1283136860721254471) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

1 Like

can you show me the route code you are calling?

1 Like

You mean where I’m calling this function?

1 Like

That doesn’t look like a default route from us so I’m assuming that you created a custom route and controller within Strapi.

That’s what I’m looking for

1 Like

Ah, yeah kinda :smiling_face_with_tear: holup lemme get the file, give me a sec tho I’m home so imma have to remote I to my PC :skull:

For context, I got my project running with next-auth using Prisma and a postgres db and now I’m trying to see if I can use Strapi instead but without changing the rest of my code
Using Credentials and google oauth
One sec imma get you the relevant files :saluting_face:

Wait no I re-read the message
What I’m trying to do in this code is, I have a verification token collection type and here I’m trying to delete a specific entry using it’s ID.

No rush I’m about to off work for today so worst case I can take a look tomorrow

Ah alright

Can you try testing that request in something like Postman (just a basic REST client)

to confirm you see the same behavior there?

I’d love to, but it would have to be tomorrow, I’ve never used it before so I’d have to figure it out first and it’s just easier on PC than on Android via anydesk :skull:

And because after compression etc the screenshots are basically near impossible to see, this is the collection type I’m trying to delete an entry of, it accepts an email(required string) a token (required string) and an “expires” value (required datetime)

Basically what I’m trying to do is, I’m checking if there’s an existing verification token for a certain email address, if it does, it should be deleted and a new one should be created.
I am able to find the token using an email address, I get it’s ID, try to delete it (and fail) and then create a new one (which also works)

Definitely will try postman and come back to ya tomorrow but it feels super weird that it’s not deleted after getting a 204

Forgot to mention that I’m using strapi v5 rc in case it helps, rather important info to omitt…

Good morning :slightly_smiling_face:

Getting the same behaviour using Postman

here’s the rest of the code in case it’s needed:

also, some additional info i’m now logging for troubleshooting purposes

Request URL: http://localhost:1337/api/verification-tokens/8
Response Status: 204
Response Headers: HeadersList {
  cookies: null,
  [Symbol(headers map)]: Map(15) {
    'access-control-allow-origin' => { name: 'Access-Control-Allow-Origin', value: '' },
    'content-security-policy' => {
      name: 'Content-Security-Policy',
      value: "connect-src 'self' https:;img-src 'self' data: blob: https://market-assets.strapi.io;media-src 'self' data: blob:;default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline'"
    },
    'referrer-policy' => { name: 'Referrer-Policy', value: 'no-referrer' },
    'strict-transport-security' => {
      name: 'Strict-Transport-Security',
      value: 'max-age=31536000; includeSubDomains'
    },
    'x-content-type-options' => { name: 'X-Content-Type-Options', value: 'nosniff' },
    'x-dns-prefetch-control' => { name: 'X-DNS-Prefetch-Control', value: 'off' },
    'x-download-options' => { name: 'X-Download-Options', value: 'noopen' },
    'x-frame-options' => { name: 'X-Frame-Options', value: 'SAMEORIGIN' },
    'x-permitted-cross-domain-policies' => { name: 'X-Permitted-Cross-Domain-Policies', value: 'none' },
    'vary' => { name: 'Vary', value: 'Origin' },
    'access-control-allow-credentials' => { name: 'Access-Control-Allow-Credentials', value: 'true' },
    'x-powered-by' => { name: 'X-Powered-By', value: 'Strapi <strapi.io>' },
    'date' => { name: 'Date', value: 'Wed, 11 Sep 2024 07:16:48 GMT' },
    'connection' => { name: 'Connection', value: 'keep-alive' },
    'keep-alive' => { name: 'Keep-Alive', value: 'timeout=5' }
  },
  [Symbol(headers map sorted)]: null
}
Token successfully deleted!

token’s permissions (among others)

and I can also happily share a github repo if needed.

the further i continue with my project, the more I fall onto similar behaviour; Now I got a 200 response on a PUT request to update the info of a User, but the entry is not updated…