I am trying to retrieve a Confluence page using this script line:
Invoke-RestMethod -Method GET -User user:pswd
-Uri "https://confluenceURL/rest/api/content/7700576?expand=body.storage"
But get this error:
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At line:1 char:1
+ Invoke-RestMethod -Method GET -User user:passwd -Uri "https ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Does anyone know what I'm doing wrong here ? I know the page exists and I have access to it.
Hello Robert and welcome to the Community,
It seems as though your powershell invoke-restmethod call is formatted properly. With that said, your response code of 404 is tell you that the user you’re authenticating as does not have permission to view the content.
Here is the documentation for the Get Content Calls and Get Content by ID.
A couple things to try;
Other options instead of using username:password would be to use an API token. Here is how to get an API Token.
From the URI you are attempting to hit it seems you have the wrong verbiage after expand, the formatting should be:
https://confluenceURL/rest/api/content/7700576?expand=body.view
Please let us know if this helps to get your REST API calls working.
Regards,
Stephen Sifers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.