Hi @Diksha Yadav
Did you forget to pass the mailbox folder id? It should be:
GET /users/{id | userPrincipalName}/mailFolders/{id}/messages
If the target user only delegates you to access their specific mailbox folder, then you will be able to list all the mails in that folder. If the target user delegates you to access their entire mailbox, then you will be able to list all the mails of the target user. vice versa.
Reference: Get Outlook messages in a shared or delegated folder.
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.