trying to get access token from graph api to be able to send mail from app.

Pat Sinclair 20 Reputation points
2023-09-15T20:19:13.96+00:00

when trying to get the access token so that I can call graph mail.send, I am getting a 400 bad request.

below is the rest api I am calling:

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token?client_id={app id}&scope={have tried pointing to graph and the api:appid}&client_secret={tried value and secret id}&grant_type=client_credentials

no matter what I try I get a 400 error...

Have been going round and round with this trying to get the app to work, need to be able to send custom emails.

Thanks up front for any assistance.

Regards,

Pat

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,786 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 41,126 Reputation points
    2023-09-18T03:13:36.39+00:00

    Hi @Pat Sinclair

    Don't try to put the app ID in the scope, this token should only be used to call the graph API and not other web APIs.

    Also, this is a POST request instead of a GET request, don't try to request the URL in the browser, you can send the token request in an API client tool such as Postman.

    POST https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/token           
    Content-Type: application/x-www-form-urlencoded
    
    client_id={client id}
    &scope=https://graph.microsoft.com/.default
    &client_secret={client secret}
    &grant_type=client_credentials
    

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Vahid Ghafarpour 21,085 Reputation points
    2023-09-15T20:51:12.6166667+00:00

    You can use tools like Postman or cURL to test your token request outside of your application, which can help isolate the issue.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.