Consume NextJS API endpoint from external cron job

What I am trying to achieve:

  1. Have existing NextJS v14 app that uses Auth0
  2. Set up cron job via Azure Function that consumes protected endpoint in NextJS app

What I have done so far:

  1. Have NextJS app running and protected via auth0
  2. Created machine-to-machine (m2m) application
  3. Tried to consume NextJS endpoint using access token generated by m2m app

I am unable to successfully access the endpoint. The NextJS withApiAuthRequired middleware returns 401 error “The user does not have an active session or is not authenticated”.

What am I missing?