Friday, October 9, 2026

graph sharepoint


SET TenantId TO $'''5a2c87d9-ad1d-4d88-85ef-f5a3c30ca040'''

SET ClientId TO $'''473fd5ed-08fe-4c90-82a6-d3180546e5fd'''

SET ClientSecret TO $'''StB8Q~lB86O-7SxBKUm6Jjzf0guSFYtYqWrTBcv3'''

SET SiteHost TO $'''sreekanth10.sharepoint.com'''

SET SitePath TO $'''/sites/pub'''

SET TargetFileName TO $'''customlistcss.css'''

SET DownloadFolderPath TO $'''C:\\Users\\usree\\Downloads\\graphdownlaod'''

SET UA TO $'''Mozilla/5.0 (Windows NT 10.0; Win64; x64)'''

Web.InvokeWebService.InvokeWebService Url: $'''https://login.microsoftonline.com/%TenantId%/oauth2/v2.0/token''' Method: Web.Method.Post Accept: $'''application/json''' ContentType: $'''application/x-www-form-urlencoded''' RequestBody: $'''client_id=%ClientId%&client_secret=%ClientSecret%&scope=https%%3A%%2F%%2Fgraph.microsoft.com%%2F.default&grant_type=client_credentials''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> TokenHeaders Response=> TokenResponse StatusCode=> TokenStatus

Variables.ConvertJsonToCustomObject Json: TokenResponse CustomObject=> TokenObj

SET AccessToken TO TokenObj['access_token']

Web.InvokeWebService.InvokeWebService Url: $'''https://graph.microsoft.com/v1.0/sites/%SiteHost%:%SitePath%''' Method: Web.Method.Get Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization: Bearer %AccessToken%''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> SiteHeaders Response=> SiteResponse StatusCode=> SiteStatus

Variables.ConvertJsonToCustomObject Json: SiteResponse CustomObject=> SiteObj

SET SiteId TO SiteObj['id']

Web.InvokeWebService.InvokeWebService Url: $'''https://graph.microsoft.com/v1.0/sites/%SiteId%/drive/root:/%TargetFileName%''' Method: Web.Method.Get Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization: Bearer %AccessToken%''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> ItemHeaders Response=> ItemResponse StatusCode=> ItemStatus

Variables.ConvertJsonToCustomObject Json: ItemResponse CustomObject=> ItemObj

SET FileName TO ItemObj['name']

SET DownloadUrl TO ItemObj['@microsoft.graph.downloadUrl']

Web.DownloadFromWeb.DownloadToFile Url: DownloadUrl FilePath: $'''%DownloadFolderPath%\\%FileName%''' ConnectionTimeout: 120 FollowRedirection: True ClearCookies: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False DownloadedFile=> DownloadedFile

Display.ShowMessageDialog.ShowMessage Title: $'''SharePoint download''' Message: $'''Downloaded: %DownloadedFile%''' Icon: Display.Icon.Information Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed2


===============================================================

SET TenantId TO $'''5a2c87d9-ad1d-4d88-85ef-f5a3c30ca040'''

SET ClientId TO $'''473fd5ed-08fe-4c90-82a6-d3180546e5fd'''

SET ClientSecret TO $'''StB8Q~lB86O-7SxBKUm6Jjzf0guSFYtYqWrTBcv3'''

SET SiteHost TO $'''sreekanth10.sharepoint.com'''

SET SitePath TO $'''/sites/pub'''

SET TargetFileName TO $''''''

SET DownloadFolderPath TO $'''C:\\Users\\usree\\Downloads\\graphdownlaod'''

SET UA TO $'''Mozilla/5.0 (Windows NT 10.0; Win64; x64)'''

Web.InvokeWebService.InvokeWebService Url: $'''https://login.microsoftonline.com/%TenantId%/oauth2/v2.0/token''' Method: Web.Method.Post Accept: $'''application/json''' ContentType: $'''application/x-www-form-urlencoded''' RequestBody: $'''client_id=%ClientId%&client_secret=%ClientSecret%&scope=https%%3A%%2F%%2Fgraph.microsoft.com%%2F.default&grant_type=client_credentials''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> TokenHeaders Response=> TokenResponse StatusCode=> TokenStatus

Variables.ConvertJsonToCustomObject Json: TokenResponse CustomObject=> TokenObj

SET AccessToken TO TokenObj['access_token']

Web.InvokeWebService.InvokeWebService Url: $'''https://graph.microsoft.com/v1.0/sites/%SiteHost%:%SitePath%''' Method: Web.Method.Get Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization: Bearer %AccessToken%''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> SiteHeaders Response=> SiteResponse StatusCode=> SiteStatus

Variables.ConvertJsonToCustomObject Json: SiteResponse CustomObject=> SiteObj

SET SiteId TO SiteObj['id']

Web.InvokeWebService.InvokeWebService Url: $'''https://graph.microsoft.com/v1.0/sites/%SiteId%/drive''' Method: Web.Method.Get Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization: Bearer %AccessToken%''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> DriveHeaders Response=> DriveResponse StatusCode=> DriveStatus

Variables.ConvertJsonToCustomObject Json: DriveResponse CustomObject=> DriveObj

SET DriveId TO DriveObj['id']

SET FileName TO $''''''

SET DownloadUrl TO $''''''

IF IsEmpty(TargetFileName) THEN

    Web.InvokeWebService.InvokeWebService Url: $'''https://graph.microsoft.com/v1.0/drives/%DriveId%/root/children''' Method: Web.Method.Get Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization: Bearer %AccessToken%''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> ListHeaders Response=> ListResponse StatusCode=> ListStatus

    Variables.ConvertJsonToCustomObject Json: ListResponse CustomObject=> ListObj

    LOOP FOREACH CurrentItem IN ListObj['value']

        Variables.ConvertCustomObjectToJson CustomObject: CurrentItem Json=> ItemJson

        IF Contains(ItemJson, $'''\"file\"''', False) THEN

            SET FileName TO CurrentItem['name']

            SET DownloadUrl TO CurrentItem['@microsoft.graph.downloadUrl']

            EXIT LOOP

        END

    END

ELSE

    Web.InvokeWebService.InvokeWebService Url: $'''https://graph.microsoft.com/v1.0/drives/%DriveId%/root:/%TargetFileName%''' Method: Web.Method.Get Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization: Bearer %AccessToken%''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: True EncodeRequestBody: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> ItemHeaders Response=> ItemResponse StatusCode=> ItemStatus

    Variables.ConvertJsonToCustomObject Json: ItemResponse CustomObject=> ItemObj

    SET FileName TO ItemObj['name']

    SET DownloadUrl TO ItemObj['@microsoft.graph.downloadUrl']

END

IF IsEmpty(DownloadUrl) THEN

    Display.ShowMessageDialog.ShowMessage Title: $'''SharePoint download''' Message: $'''No file found in the library root.''' Icon: Display.Icon.ErrorIcon Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed

    EXIT Code: 0

END

Web.DownloadFromWeb.DownloadToFile Url: DownloadUrl FilePath: $'''%DownloadFolderPath%\\%FileName%''' ConnectionTimeout: 120 FollowRedirection: True ClearCookies: False UserAgent: UA Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False DownloadedFile=> DownloadedFile

Display.ShowMessageDialog.ShowMessage Title: $'''SharePoint download''' Message: $'''Downloaded: %DownloadedFile%''' Icon: Display.Icon.Information Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed2


No comments:

Post a Comment

Featured Post

Exchange Online - Archive Emails

Archive Emails Older Than X Years in Exchange Online – The Server-Side Way (MRM + PowerShell) Scenario: A user's mailbox is almost full...

Popular posts