AtlassianPS / ConfluencePS

Confluence REST API (including Cloud) via PowerShell
https://AtlassianPS.org/module/ConfluencePS
MIT License
152 stars 41 forks source link

Confluence returned HTTP error 400 - BadRequest #158

Open braveadmin opened 5 years ago

braveadmin commented 5 years ago

Description

I noticed that Set-ConfluencePage command doesn't work at all, maybe for a bug.

If I do a get of a certain PageID it works without problem, but when i do the following command it prompts me the following bellow

Steps To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Screenshots

image

Your Environment

Get-Module ConfluencePS -ListAvailable | Select Name, Version
Name         Version
----         -------
ConfluencePS 2.3.6  

$PSVersionTable
Name                           Value                                           
----                           -----                                           
PSVersion                      5.1.16299.785                                   
PSEdition                      Desktop                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
BuildVersion                   10.0.16299.785                                  
CLRVersion                     4.0.30319.42000                                 
WSManStackVersion              3.0                                             
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1  

Confluence Server:

lipkau commented 5 years ago

Please update the "Your Environment" in the template.

lipkau commented 5 years ago

Please run the command with -Debug enabled:

Set-ConfluencePage -PageId 616493147 -Body 'test' -debug

enter suspend mode on the 2nd time this message shows up:

DEBUG: [Invoke-Method] Executed WebRequest. Access $webResponse to see details

(the first is for Get-Page and the 2nd for Set-Page)

Once in suspend, please post here the output of

$iwParameters
$body
braveadmin commented 5 years ago

This is the output:

PS C:\Windows\system32>> Set-ConfluencePage -PageID $PageID -Body $Body -Debug
DEBUG: [Set-ConfluencePage] ParameterSetName: byParameters
DEBUG: [Set-ConfluencePage] PSBoundParameters: 
Key                                            Value
---                                            -----
PageID                                     616493147
Body                                            Test
Debug                                           True
apiURi            https://confluence.ntt.eu/rest/api
Credential System.Management.Automation.PSCredential

DEBUG: [Get-Page] ParameterSetName: byId
DEBUG: [Get-Page] PSBoundParameters: 
Key        Value                                    
---        -----                                    
PageID     {616493147}                              
ApiURi     https://confluence.ntt.eu/rest/api       
Credential System.Management.Automation.PSCredential

DEBUG: [Invoke-Method] ParameterSetName: __AllParameterSets
DEBUG: [Invoke-Method] PSBoundParameters: 
Key                                                              Value
---                                                              -----
First                                             18446744073709551615
GetParameters                                          {expand, limit}
Method                                                             Get
Skip                                                                 0
URi               https://confluence.ntt.eu/rest/api/content/616493147
IncludeTotalCount                                                False
Credential                   System.Management.Automation.PSCredential
OutputType                                           ConfluencePS.Page

DEBUG: [Invoke-Method] Using $GetParameters: 
Name                           Value                                           
----                           -----                                           
expand                         space,version,body.storage,ancestors            
limit                          25                                              

DEBUG: [Invoke-Method] Executed WebRequest. Access $webResponse to see details
PS C:\Windows\system32>>> $iwParameters
$body

Name                           Value                                           
----                           -----                                           
First                          18446744073709551615                            
GetParameters                  {expand, limit}                                 
Method                         Get                                             
Skip                           0                                               
Uri                            https://confluence.ntt.eu/rest/api/content/61...
IncludeTotalCount              False                                           
Credential                     System.Management.Automation.PSCredential       
OutputType                     ConfluencePS.Page   
lipkau commented 5 years ago

you stopped at the first message

DEBUG: [Invoke-Method] Executed WebRequest. Access $webResponse to see details

I need the $body and $iwParameters of the 2nd time that message is shown

braveadmin commented 5 years ago

sorry, this is the result:

DEBUG: [Set-ConfluencePage] ParameterSetName: byParameters
DEBUG: [Set-ConfluencePage] PSBoundParameters: 
Key                                            Value
---                                            -----
PageID                                     616493147
Body                                            Test
Debug                                           True
apiURi            https://confluence.ntt.eu/rest/api
Credential System.Management.Automation.PSCredential

DEBUG: [Get-Page] ParameterSetName: byId
DEBUG: [Get-Page] PSBoundParameters: 
Key        Value                                    
---        -----                                    
PageID     {616493147}                              
ApiURi     https://confluence.ntt.eu/rest/api       
Credential System.Management.Automation.PSCredential

DEBUG: [Invoke-Method] ParameterSetName: __AllParameterSets
DEBUG: [Invoke-Method] PSBoundParameters: 
Key                                                              Value
---                                                              -----
First                                             18446744073709551615
GetParameters                                          {expand, limit}
Method                                                             Get
Skip                                                                 0
URi               https://confluence.ntt.eu/rest/api/content/616493147
IncludeTotalCount                                                False
Credential                   System.Management.Automation.PSCredential
OutputType                                           ConfluencePS.Page

DEBUG: [Invoke-Method] Using $GetParameters: 
Name                           Value                                           
----                           -----                                           
expand                         space,version,body.storage,ancestors            
limit                          25                                              

DEBUG: [Invoke-Method] Executed WebRequest. Access $webResponse to see details
DEBUG: [Set-ConfluencePage] Content to be sent: 
Name                           Value                                           
----                           -----                                           
type                           page                                            
version                        {number}                                        
ancestors                      {}                                              
body                           {storage}                                       
title                          Llistat IP - Cloud Nexica - Test                

DEBUG: [Invoke-Method] ParameterSetName: __AllParameterSets
DEBUG: [Invoke-Method] PSBoundParameters: 
Key                                                                       Value
---                                                                       -----
Method                                                                      Put
Credential                            System.Management.Automation.PSCredential
URi                        https://confluence.ntt.eu/rest/api/content/616493147
Body                                                                       {...
OutputType                                                    ConfluencePS.Page

DEBUG: [Invoke-Method] Executed WebRequest. Access $webResponse to see details
PS C:\Windows\system32>>>> $Body
{
    "type":  "page",
    "version":  {
                    "number":  4
                },
    "ancestors":  [

                  ],
    "body":  {
                 "storage":  {
                                 "representation":  "storage",
                                 "value":  "Test"
                             }
             },
    "title":  "Llistat IP - Cloud Nexica - Test"
}

PS C:\Windows\system32>>>> $iwParameters

Name                           Value                                           
----                           -----                                           
Method                         Put                                             
Credential                     System.Management.Automation.PSCredential       
Uri                            https://confluence.ntt.eu/rest/api/content/61...
Body                           {...                                            
OutputType                     ConfluencePS.Page 
lipkau commented 5 years ago

I can't figure out what is going on. What does this return?

get-confluencepage -PageID 616493147 | select -exclude body
braveadmin commented 5 years ago
PS C:\Users\braveadmin> get-confluencepage -PageID 616493147 | select -exclude body

ID         Status    Title                                SpaceKey        Version   
--         ------    -----                                --------        -----
616493147            Llistat IP - Cloud Nexica - Test     AOC             3   
lipkau commented 5 years ago

does this happen to every page on that wiki server? or in that same space?

braveadmin commented 5 years ago

I tried with other pages, even with test pages created exclusively to test this. In every case I got the same error. I can do a Get-ConfluencePage but Set-ConfluencePage doesn't work.

lipkau commented 5 years ago

@braveadmin : can you confirm that this still happens on the latest version? (2.4.0)

@brianbunke : can you reproduce this?

braveadmin commented 5 years ago

Hi @lipkau do you mean ConfluencePS version?

lipkau commented 5 years ago

yes

braveadmin commented 5 years ago

I got the same error. "Edit content id mismatch".

brianbunke commented 5 years ago

I cannot reproduce. Set-ConfluencePage -PageId 616493147 -Body 'test test' works as expected for me on ConfluencePS 2.4.0 and Confluence Server 6.10.0. My $Body and $iwParameters debug output looks identical.

braveadmin commented 5 years ago

Any suggestion on what could be going wrong? @brianbunke @lipkau

braveadmin commented 5 years ago

which version of powershell did you use to test it?

lipkau commented 5 years ago

I can run it successfully on PSv5.1 and v6.1 against a Cloud server and an On-Premise Server v6.2.4

braveadmin commented 5 years ago

Which minimum version of Confluence Server is compatible with ConfluencePS? @brianbunke

lipkau commented 5 years ago

There is no way to really know this. I can be wrong, but would expect all version > 6 to work properly. I have tried finding old versions of the API documentation, but this is not trivial

lipkau commented 5 years ago

What is the version of the confluence server?

You should be able to see it in the footer of pretty much every page

rjdlobik commented 5 years ago

I'm also receiving a 400 bad request when attempting to retrieve a page by label. I've included the request and response below:

$response = Get-ConfluencePage -Label 'noarchive-single'

WARNING: Confluence returned HTTP error 400 - BadRequest Invoke-Method : Could not parse cql : type=page AND label=noarchive-single At C:\Program Files\WindowsPowerShell\Modules\ConfluencePS\2.5.0\ConfluencePS.psm1:772 char:17

MortenRei commented 4 years ago

I have the exact samme problem as the rest here. Did anyone manage to solve the problem?

ehrenfeu commented 4 years ago

@rjdlobik are you sure you are referring to the same problem here? Your issue looks more like the hyphen quoting problem described in #175