Hello experts,
I have received following error message when I am trying to use Rest API by powershell to create a new confluence page.
{"message":"Current user not permitted to use Confluence","statusCode":403}
But I can do it successfully before with the same codes, the last successful page created was on 02/18/2023. Following is the code:
#################################
$pair = "miansheng.wu@commscope.com:generatedToken"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$auth = "Basic " + $encodedCreds;
$Headers = @{
Authorization = $auth; 'Content-Type' = 'application/json'
}
$uri = "https://arrisworkassure.atlassian.net/wiki/rest/api/content"
Invoke-WebRequest -Headers $Headers -Uri $uri -Method Post -Body '{"type":"page","title":"Test page","ancestors":[{"id":3734306868}], "space":{"key":"TEAM"},"body":{"storage":{"value":"Test body","representation":"storage"}}}'
#################################
Could you please help me? This issue blocks me a lot now.
Thanks,
Ken
This issue is resolved. Because our Cloud Site at some point is changed from arrisworkassure.atlassian.net to cloud-cs.atlassian.net, change the $uri = "https://arrisworkassure.atlassian.net/wiki/rest/api/content" to be "https://cloud-cs.atlassian.net/wiki/rest/api/content" and then page can be created successfully.
Thank you for all your help.
Hi Ken,
I think I see a problem with the way you are encoding credentials here. Please refer to our documentation in Basic auth for REST APIs. You code seems to be using this line:
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
When I think instead it should look like this:
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($pair))
Note the only difference here is we're using UTF8 instead of ASCII character encoding, but I have seen this difference trip up some other implementations before.
The error you are seeing here fits with this idea. When Confluence or Jira does not receive valid encoded credentials using basic auth, it can still attempt to make the request as if it was an anonymous user. In which case, anonymous users typically don't have access to this content and in turn the HTTP 403 error reflects this.
Try this and let me know the results.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Andy,
Thanks so much for your reply.
I have tried 'UTF8' encoding but the result is the same.
Then I tried 'Unicode' and other encodings and they didn't work either.
Thanks,
Ken
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ken,
I see that you have a support case for this over in https://getsupport.atlassian.com/servicedesk/customer/portal/48/PCS-187273
I recommend working with our support team there to determine if this problem is specific to your cloud environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried to use 'curl' instead, but the result is the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.