简体   繁体   中英

Power BI Powershell Export to PDF Script not Working

Below code I m using to export pdf.When i pass direct value value in line 5 then its working but when im pass $id in line 5,it snot working.

1 $uri = "https://api.powerbi.com/v1.0/myorg/reports/$Report_ID/ExportTo"

2 $body = "{ "format ": "pdf "}"

3 $FileExport = Invoke-RestMethod -Uri $uri –Headers $auth_header –Method POST -body $body

4 $id = $FileExport.id

5 $uri = "https://api.powerbi.com/v1.0/myorg/reports/$Report_ID/exports/$id/file"

6 Invoke-RestMethod -Method GET -Uri $uri –Headers $auth_header -OutFile "\Desktop\PDF\test.pdf"

Below error

*Invoke-RestMethod: The remote server returned an error: (400) Bad Request. At line:79 char:2

  • Invoke-RestMethod -Method GET -Uri $uri –Headers $auth_header -OutFi...
  •  + CategoryInfo: InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId: WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand*

$uri = "https://api.powerbi.com/v1.0/myorg/reports/$Report_ID/exports/$id/file"

This is a string, you have to break it up or it will be read literally as part of the string.

$uri = "https://api.powerbi.com/v1.0/myorg/reports/" + $Report_ID + "/exports/" + $id + "/file"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM