0
votes

Below code I m using to export pdf.When i pass direct value value in line 5 then its working but when i m 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*
    
1
If I resolved this, don't forget to "mark as answer".shadow2020

1 Answers

0
votes

$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"