I have been trying to get emails from another user in my domail in order to migrate it, using the google nodejs library. My account is superadmin and my API has wide-domain delegation permission enable with the following scopes:
"https://www.googleapis.com/auth/apps.groups.migration",
"https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.settings.sharing"
I have logged into the API usin an impersonate access
async function initializeGmail(emailToImpersonate) {
const auth = await getAuth(emailToImpersonate);
return google.gmail({
version: 'v1',
auth
});
}
async function getAuth(emailToImpersonate) {
const jwtClient = new google.auth.JWT(
client_email,
null,
private_key,
SCOPES,
emailToImpersonate
);
await jwtClient.authorize();
return jwtClient;
}
I have added delegation permitions in the account I want to migrate so I can access its emails from my main account
const requestBody = {
delegateEmail: user.email,
verificationStatus: 'accepted'
}
await gmail.users.settings.delegates.create({userId, requestBody})
I request the emails of the account to migrate and I get the following error
const gmail = await initializeGmail(userEmail);
const messages = (await gmail.users.messages.list({auth, userId:userEmail})).data.messages;
code: 403,
errors: [
{
domain: 'global',
reason: 'forbidden',
message: 'Delegation denied for sysadmin@boatjump.com'
}
]
Any help or ideas will be highly appreciated