MS Graph Explorer Equivalent Curl Request (for debug sanity)

Y CHANG 0 Reputation points
2024-11-28T08:12:12.6766667+00:00

It seems graph api calls from curl do not match what the graph explorer interface does. For example, this curl request below would intermittently return a null [] list but once I call the same request in graph explorer interface, and then try the same curl below, it will return a non-null list.

curl --location 'https://graph.microsoft.com/v1.0/me/drive/root/search(q='\''.obj'\'')?select=name%2Cid' \ 
--header 'Content-Type: application/json' \ 
--header 'Authorization: ••••••'

What is the actual equiv curl request that graph explorer is calling? FYI USING

https://graph.microsoft.com/v1.0/me/drive/root/search(q=%23.obj%23)

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.driveItem)","value":[]}

Microsoft 365 and Office | OneDrive | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Danstan Onyango 3,911 Reputation points Microsoft Employee
    2024-12-03T07:12:09.53+00:00

    Your curl seems to have some syntax errors. Below is the correct curl for the example.

    curl --request GET \
      --url 'https://graph.microsoft.com/v1.0/me/drive/root/search(q=%27.obj%27)?select=name%2Cid' \
      --header 'Authorization: Bearer .....' \
      --header 'Content-Type: application/json'
    

    Often times when you need to execute scripts against Graph API like curl, PowerShell SDK for Graph does a better job if the environment supports it. If the Environment your code will run in does not support PowerShell, then you just need to replace the URL on Graph Explorer with the URL part of the curl.

    Learn more about Graph API PowerShell SDK https://learn.microsoft.com/en-us/powershell/microsoftgraph/?view=graph-powershell-1.0


Your answer

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