Forum Discussion
Miike
Jul 04, 2024Brass Contributor
Terms of Use file download? How to access this via the Graph API
Hi All,
I've started to play with Microsoft Graph in further details, but I'm having trouble with Terms of Use, I can retrieve the configuration and details on the file, but it would be great if I could programmatically download the file.
The following endpoint returns data:
- Policy and file - https://graph.microsoft.com/v1.0/agreements/{id}?$expand=files
However, the FileData attribute is empty. I can download the file fine from the portal, but it would be great to retrieve a URL or code to convert into the file type itself.
I've seen further documentation here, but not sure how to proceed:
agreementFileData resource type - Microsoft Graph v1.0 | Microsoft Learn
Any tips?
Thanks!
- MiikeBrass ContributorI found it, I had to use dev tools in edge, request a file then look to see what it was requesting.
The following grabs the TOU file and converts it into the appropriate file:
# Make the request to get the file data
$fileDataResponse = Invoke-MgGraphRequest -Method GET -uri "https://graph.microsoft.com/v1.0/agreements/$($termsId)/file/localizations/$($fileId)/fileData/data" -ContentType "application/json"
# Decode the file data from Base64
$fileBytes = [Convert]::FromBase64String($fileDataResponse.value)
# Construct the full path to save the file
$outputFilePath = Join-Path -Path "$ExportPath\Terms of Use" -ChildPath $fileName
# Write the file data to the file
[System.IO.File]::WriteAllBytes($outputFilePath, $fileBytes)