Programatically rename space home page title
Asked by yevhen_rudenko:

Hi there,

I would like to programatically rename space home page title (not sure if I call that stuff correctly, screen attached)

![HomePage.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176220i155B7E513EFD2BCC/image-size/large?v=v2&px=999 "HomePage.jpg")

I tried the following REST API:

PUT /rest/space/{spaceKey}

![resr.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176221i5600952175D4F3EC/image-size/large?v=v2&px=999 "resr.jpg")

When I send the following json as a request body then everything works fine, name and description are updated  

```
{

    "name": "Space name",

     "description": {

        "plain": {

            "value": "New description",

            "representation": "plain"

        }

     }

}
```

However, when I send a json like this

```
{

    "name": "Space name",

     "description": {

        "plain": {

            "value": "New description",

            "representation": "plain"

        }

     },

     "homepage": {

        "title": "New Home Page"

    }

}
```

I get the following response:  

```
{

    "statusCode": 400,

    "data": {

        "authorized": true,

        "valid": false,

        "allowedInReadOnlyMode": true,

        "errors": [

            {

                "message": {

                    "translation": "Cannot update space homepage to page in space with key: TEST",

                    "args": []

                }

            }

        ],

        "successful": false

    },

    "message": "Cannot update Space",

    "reason": "Bad Request"

}
```

I understand that it is a bad request, but I can't figure out what exactly should be sent as a body to have space home page title updated?

Thanks,

Yevhen


Answers:
author: WW
body: I *think*what you're trying to do is change the Homepage selection on the space's Overview -\> Edit space details screen, but through the REST API instead of the screen. If that is correct, then here's what you do.

First, run the Get for the space to see what its details are, something like:

```
https://<myurl>/rest/api/space/KEY?expand=homepage
```

You'll see in the documentation that **homepage is of type array**, so it's not just the title.

Unfortunately, Confluence's documentation is not nearly as good as Jira's, and this particular piece lacks detail, such as what other fields are required to update the homepage field of a space, and there are a lot. Here's what I got when I ran the Get (*I put in a lot of fake values, but the fields are real*):

```
"homepage":{
"id":"987654321"
,"type":"page"
,"status":"current"
,"title":"Test Space Home"
,"extensions":{"position":"none"}
,"_links": {
    "webui":"/display/KEY/Test+Space+Home"
    ,"edit":"/pages/resumedraft.action?draftId=123456789"
    ,"tinyui":"/x/pYQoTw"
    ,"self":"https://myurl/rest/api/content/987654321"
    }
,"_expandable":{
    "container":"/rest/api/space/KEY"
    ,"metadata":""
    ,"operations":""
    ,"children":"/rest/api/content/987654321/child"
    ,"restrictions":"/rest/api/content/987654321/restriction/byOperation"
    ,"history":"/rest/api/content/987654321/history"
    ,"ancestors":""
    ,"body":""
    ,"version":""
    ,"descendants":"/rest/api/content/987654321/descendant"
    ,"space":"/rest/api/space/KEY"
    }
}
```

And fortunately, I tested it, and it only needs the page Id to work. I didn't test with the title, but feel free to. So here's the Json you need to send (or something like it):

```
{
??? "name": "Test Space Temp",
??? "description": {
??????? "plain": {
??????????? "value": "New description",
??????????? "representation": "plain"
??????????? }
??? },
??? "homepage": {
??????? "id": "11112222"
??? }
}
```

Just put your homepage's id instead of 11112222.

You just needed a **couple of little curly brackets**, for the most part.

comments: author: yevhen_rudenko
body: [@WW](/t5/user/viewprofilepage/user-id/1209024)

Thanks for your reply.

I checked that when I send

```
{
     "homepage": {
        "id": "11112222",
        "title": "HomePageNewTitle"
    }
}
```

the server simply ignores **title** as it needs **id** only to identify the page to be set as the homepage.  
I actually need to change only homepage title just like if to click Edit button  
![edit.png](https://community.atlassian.com/t5/image/serverpage/image-id/176658iC8E912692F398BFB/image-size/large?v=v2&px=999 "edit.png")  
![Edit - HomePage.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176657iF9C7DD1C32D48352/image-size/large?v=v2&px=999 "Edit - HomePage.jpg")  
I assume there might be another REST endpoint that I didn't manage to find yet.


author: WW
body: Ah, so that's what I originally thought your question was asking, but then I thought maybe you were asking how to change the homepage like from the Edit space details screen, since that's kind of tricky.

So, the problem you're having is that you're using the wrong REST API call. You're trying to update the space details rather than the page information. The homepage is just like any other page when it comes to editing its content, and any page can be the homepage.

You'd just need to [use](https://docs.atlassian.com/ConfluenceServer/rest/7.15.0/#api/content-update):

```
PUT /rest/api/content/{contentId}
```

instead of:

```
PUT /rest/space/{spaceKey}
```


author: yevhen_rudenko
body: [@WW](/t5/user/viewprofilepage/user-id/1209024)

When manually click **Edit** button and then **Update**the very end of the url changes accordingly to new title (circles #1 and #2 on the screen)

![hp11.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176830i1C279FD41023A40B/image-size/large?v=v2&px=999 "hp11.jpg")

Then if refresh F5 then I get another update (circle #3)

![hp12.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176831i1B98035F6EB1FBA3/image-size/large?v=v2&px=999 "hp12.jpg")

I tried then

```
PUT /rest/api/content/{contentId}
```

The json body looks like this  

```
{
    "title": "HomePageREST",
    "type":"page",
    "version": {
        "number":30
    }
}
```

As a result I have the following

![hp-rest.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176832i6A7DF68E21639E72/image-size/large?v=v2&px=999 "hp-rest.jpg")

Now the url (circle #1) and whatever that section is (circle #3, which I don't really care about, but still...) have been changed, but the title (circle #2) has never changed.

I also checked if this title is a part of page body and it looks like it is not

![hp-body.png](https://community.atlassian.com/t5/image/serverpage/image-id/176833i95EAA2BB4F4075D0/image-size/large?v=v2&px=999 "hp-body.png")

Probably missing a property or so, don't really know what I'm doing wrong.

Another thing is that this endpoint requires **version** , which must be equal to **current version + 1,**which leads to additional GET request but that is a different story


author: WW
body: Yes, you do have to put the next version in there, which I think is stupid, bc why would you put or want anything but current version +1, and I think it has to be +1, but yes, that's another story. :)

I ran the below, and it worked for me. However, when I refreshed the page I renamed, it said it was in the trash. So, I clicked on the page from the left navigation panel, and it was renamed, and the version had been updated. I ran it again, refreshed, and it gave me this page doesn't exist, maybe you want this other page. It definitely works.

```
<baseurl>/rest/api/content/123456789
```

Json:

```
{"version":
    {
        "number":2,"minorEdit": true,"message": "Updated title"
    }
,"title":"Test Stuff"
,"type":"page"}
```

*("minorEdit": true is like unchecking the Notify watchers box in the UI)*

So, I'm not sure why it's not working for you, but it *should*work. Maybe try another browser or clear your cache? Your pages might not be reindexing properly. Maybe run a rebuild the index (after hours, and if you're a Confluence admin).

It looks like the title is just not refreshing for you for some reason, but that the URL is changing and the page really is being renamed, it's just not displaying it. I wonder if you run it, the wait a while, if it'll display correctly later on.

Well, I think I've answered the how to change the Homepage title question. Now you may have a different question - why isn't the title change displaying.


author: yevhen_rudenko
body: I've tried clearing cache, a different browser, **Confluence Admin \> Content Indexing** and click "Rebuild". Well, none of them worked.

Then I sent a GET request and yes it returned updated page title. So the value is there but at the same time kind of not.

When I refresh the page the name of the tab in Chrome changes for a while (while loading the page) to updated title but then gets back to old title

![hp-l.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/176876iB3F8FC737EEF677A/image-size/large?v=v2&px=999 "hp-l.jpg")

I then assumed something was wrong with the space.

And I tried on a different 'blank' space and everything worked for it.

The thing is that the space I need to change title of the home page for is created by REST api of **Scroll Versions for Confluence** plugin. The plugin creates a new space based on another template space and that's why I need to change the home page title as it seems there is no way to configure this while using the plugin.

But again this seems to be a different question.

[@WW](/t5/user/viewprofilepage/user-id/1209024) thank you for your support


author: WW
body: *That* might have something to do with your problem. Plugins are notorious for interfering with built-in processes.

I would press F12 on your keyboard / open your browser's Developer Console to see what's going on. Especially look for something being sent when you see that name in the tab.

Good luck!


author: yevhen_rudenko
body: Okay, so if anyone ever gets into this here is a solution:

<https://k15t.zendesk.com/hc/en-us/community/posts/4413508962964-Published-space-home-page-title>


Tags: home-page

rest-api

server

title