Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Invoke-RestMethod GET fails

Robert Knazik November 15, 2018

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.

1 answer

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 16, 2018

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.

  • STATUS 404  Returned if the calling user 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;

  • Ensure the User does have access
  • Ensure the Username and password are correct
  • Ensure the URL is correct for the content you are attempting to access.

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events