#Collection Endpoint with method: 'post' Not Found

29 messages · Page 1 of 1 (latest)

ruby frost
#

When I create an endpoint in a collection, if the method is 'post' it returns an error on the server: INFO: Not found, and on the browser: {"errors":[{"message":"Not Found"}]}

This is the code:

  {
    path: '/revoke',
    method: 'post',
    handler: async (req) => {
      return Response.json({
        message: 'REVOKE has been triggered',
      })
    },
  },
meager leaf
#

Hey @ruby frost

What endpoint path are you hitting?

#

Like what's the full url?

ruby frost
#

Ok, when I create the endpoint using method: 'post'
See screenshot

#

Using method: 'get'
See screenshot
The code:

{
  path: '/revoke',
  method: 'get',
  handler: async (req) => {
    return Response.json({
      message: 'REVOKE has been triggered',
    })
  },
},
meager leaf
#

Can you try changing your endpoint definition to include /square-payments?

ruby frost
#

Sorry, what do you mean?

meager leaf
#
{
  path: '/square-payments/revoke',
  method: 'post',
  handler: async (req) => {
    return Response.json({
      message: 'REVOKE has been triggered',
    })
  },
},
ruby frost
#

Okay, the collection already have the slug square-payments I will add what you say and see how it goes

#

It doesn't work

meager leaf
#

Can you share the full collection config where this is used

#

Yeah, shouldn't need to add collection slug to it, should be fine with just /revoke, just wanted a sanity test

#

And can you share the code that actually performs the fetch?

ruby frost
#

Here some of the code:

export const SquarePayments: CollectionConfig = {
  slug: 'square-payments',
  admin: {
    useAsTitle: 'documentName',
    defaultColumns: ['documentName'],
    group: 'Admin | Payments',
  },
  access: {
    create: isAdmin,
    update: isAdminOrHasSiteAccess(),
    read: isAdminOrHasSiteAccess(),
    delete: isAdmin,
  },
  // endpoints
  endpoints: [
    {
      path: '/revoke',
      method: 'post',
      handler: async (req) => {
        return Response.json({
          message: 'REVOKE has been triggered',
        })
      },
    },
....
#

I have 2 more endpoints the /connect and /callback, both are 'get' and they work fine

#

I think I will do the revoke access and refresh token using server actions instead.

ruby frost
meager leaf
#

No I mean the fetcher itself

#

Where you are doing fetch()

ruby frost
#

Sorry, which fetch? I would like to do a fetch inside this endpoint but this is the issue that when I use method: 'post' it's not found

meager leaf
#

You have an endoint in your api - you want to call it. You have some code somewhere that looks like this

await fetch('/revoke', { ... })

I want to see how you're calling this endpoint

ruby frost
meager leaf
#

And in the options you passed { method: 'POST' }?

#

Should be like this:

await fetch('/revoke', { method: 'POST' })

At the minimum

ruby frost
#

is it because it's a post request?

#

I meant the endpoint

#

Got ya! Thank you!

meager leaf
#

My pleasure, glad you figured it out! Should always pass a method to the fetch function if it is not a simple 'GET' request