Created
January 22, 2026 06:13
-
-
Save darryllee/8fc3c7df28159b957cb909fb692d9f43 to your computer and use it in GitHub Desktop.
Update Page Owner using GraphQL :-P
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # GraphQL mutation to update page owner - sniffed while updating Owner in Confluence UI via Chrome Developer Panel | |
| # HOSTNAME, USERNAME, and TOKEN are stored in credentials.py | |
| import requests | |
| import credentials | |
| GRAPHQL_URL = f"{credentials.HOSTNAME}/cgraphql" | |
| def update_page_owner_graphql(page_id, new_owner_account_id): | |
| """Update page owner using GraphQL API.""" | |
| headers = { | |
| "Accept": "application/json", | |
| "Content-Type": "application/json" | |
| } | |
| query = """mutation UpdateOwnerMutation($contentId: ID!, $ownerId: String!) { | |
| updateOwner(input: {contentId: $contentId, ownerId: $ownerId}) { | |
| content { | |
| id | |
| history { | |
| ownedBy { | |
| displayName | |
| type | |
| ... on KnownUser { | |
| accountId | |
| __typename | |
| } | |
| profilePicture { | |
| path | |
| __typename | |
| } | |
| __typename | |
| } | |
| lastOwnedBy { | |
| displayName | |
| type | |
| ... on KnownUser { | |
| accountId | |
| __typename | |
| } | |
| profilePicture { | |
| path | |
| __typename | |
| } | |
| __typename | |
| } | |
| __typename | |
| } | |
| __typename | |
| } | |
| __typename | |
| } | |
| } | |
| """ | |
| # Payload format matches curl example | |
| payload = [ | |
| { | |
| "operationName": "UpdateOwnerMutation", | |
| "variables": { | |
| "contentId": page_id, | |
| "ownerId": new_owner_account_id | |
| }, | |
| "query": query | |
| } | |
| ] | |
| resp = requests.post( | |
| GRAPHQL_URL, | |
| auth=(credentials.USERNAME, credentials.TOKEN), | |
| headers=headers, | |
| json=payload | |
| ) | |
| if resp.status_code == 200: | |
| data = resp.json() | |
| # Response is an array, get first element | |
| result = data[0] if isinstance(data, list) else data | |
| if "errors" in result: | |
| print(f" ✗ GraphQL errors: {result['errors']}") | |
| return False | |
| print(f" ✓ Updated page owner via GraphQL") | |
| return True | |
| else: | |
| print(f" ✗ Failed to update owner: {resp.status_code} - {resp.text}") | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment