How to get merge request details for a given pipeline?

I want to retrieve merge request details for a specific pipeline. Since there isn’t a direct API for this, I’m leveraging two separate endpoints.

First, I call the below api to get pipeline details:
projects/:id/pipelines/:pipeline_id
From this response, I extract a property called “sha”, which (I assume) represents the commit SHA.

Next, I use this commit SHA to call the below api to fetch merge request details:
projects/:id/repository/commits/:sha/merge_requests

While this approach successfully retrieves merge request details in most cases, I’ve encountered instances where the second API call returns empty despite the pipeline being associated with a merge request.

I appreciate your support in guiding me on the correct usage of the API.