Can't return anything from Management API after successful AccessToken

Greetings,

My problem currently, that I followed specifically what on the Dashbaord is writing to acquire an access token. I even changed my application from Regular Web to Machine-To-Machine application, but even after successfully retreiving the access token with axios, i can’t get anything from the Management API through anpther axios call.
I always get 401 error.

I repeat, I acquire the accesstoken succefully.

Here’s the code for the second API call:

"use server";

import axios from "axios";
import GetAccessToken from "./GetAccessToken";

export default async function fetchApiData() {
  try {
    const token = await GetAccessToken();
    console.log(token);
    const options = {
      method: "GET",
      url: "https://REDACTED.auth0.com/api/v2/users-by-email",
      params: { email: "{REDACTED EMAIL ADDRESS}" },
      headers: {
        "content-type": "application/json",
        authorization: `Bearer ${token}`,
      },
    };
    await axios(options).then((response) => console.log(response.data));
  } catch (error) {
    console.error("Error fetching API data:", error);
  }
}

Hi @csokan.raul89

Welcome back to the Auth0 Community!

I’ve checked your tenant configuration, and it looks like you didn’t attach the permissions to the Machine Machine application in the Management API settings. Please go to Applications → Apis → Machine To Machine Applications, expand on your application, and add the necessary permissions. This should allow you to receive information from Management API

Thanks
Dawid

1 Like

@dawid.matuszczyk Thank you, it works. I just can’t believe why I wasn’t sure about this, becasue I hav ebeen looking at these settings before, but I wasn’t sure about setting them or not. Forth, i will only need to refine the scopes. Thanks again, it works.

1 Like