
We encountered a 401 Unauthorized error while generating a SharePoint OAuth access token from Business Central AL code, even though the same credentials and request worked perfectly in Postman.
In Postman, we made a POST request to:
https://accounts.accesscontrol.windows.net/<tenetnt id>/tokens/OAuth/2
with the following parameters are dummy but we have used the correct ones:
Body : x-www-form-urlencoded
abcd1234-5678-90ef-ghij-klmnopqrstuv@12345678-aaaa-bbbb-cccc-1234567890abclient_secret: XyZ6OFF+TUE0TVFCWk00fnFXNUVpQTJPc0NhLlU1TWdybTBYV2FJVA==
resource: 00000003-0000-0ff1-ce00-000000000000/mysharepointsite.sharepoint.com@12345678-aaaa-bbbb-cccc-1234567890ab
grant_type: client_credentials
Header :