Forums

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

Update page via API does not work with python

Charlie Misonne
Community Champion
April 8, 2024

Hi dear community,

I am trying to update a Confluence page with python. At first I was trying to use the Atlassian python library but I kept getting a 415 unsupported media type error.
I found this bug report so I decided to bypass the library and build a regular PUT request in Python just like Atlassian has documented on https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-put

I'm still getting the 415. It works fine with curl so I'm wondering: does this work for anyone?

Code I'm using:

 

def update_page():

    auth = HTTPBasicAuth("example@email.com", "supersecrettoken")

    headers = {

        "Accept": "application/json",

        "Content-Type": "application/json"

    }

    payload = json.dumps({

        "id": "240156673",

        "status": "current",

        "title": "My Page Title",

        "body": {

            "representation": "storage",

            "value": "Hello World"

        },

        "version": {

            "number": 5,

            "message": "new version"

  }

    })

    print(payload)

    response = requests.put(

        "http://company.atlassian.net/wiki/api/v2/pages/240156673",

        json=payload,

        headers={

        "Accept": "application/json",

        "Content-Type": "application/json"},

        auth=auth

        )

   
    print(response.status_code)

    print(response.request.body)

    print(response.request.headers)

    print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))



status = update_page()

The result is:

{
"errors": [
{
"code": "UNSUPPORTED_MEDIA_TYPE",
"detail": null,
"status": 415,
"title": "org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported"
}
]
}

 And what I think is very strange:

  • response.request.headers does not include the Content-Type sender I'm sending
  • response.request.body returns 'None'

When sending the request to https://httpbin.org/anything instead I do get my header and body returned.

 

2 answers

0 votes
Dalia El-Dib April 27, 2024

Have you found the resolution?

0 votes
marc -Collabello--Phase Locked-
Community Champion
April 10, 2024

Hi @Charlie Misonne ,

maybe you need to replace the line

```

json=payload,

```

with

```

data=payload,

```

as you've done a `json.dumps()` call.

Charlie Misonne
Community Champion
April 10, 2024

thanks for pointing that out.

I had been playing around with the different options before but json=payload or data=payload both return a 415.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence whiteboards, whiteboard templates, template contest, visual collaboration, atlassian learning, confluence community, brainstorming tools, agile planning, team productivity, confluence templates, share your template

Share Your Confluence Whiteboard Template for a Chance to Be Featured in the Product! 🏆

Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.

Share your template today!
AUG Leaders

Atlassian Community Events