# Check if child page already exists using Confluence REST API (JavaScript)

**URL:** <https://community.developer.atlassian.com/t/check-if-child-page-already-exists-using-confluence-rest-api-javascript/53718>\
**Category:** Confluence Development\
**Tags:** rest-api, jira-server\
**Created:** [November 16, 2021, 4:34pm UTC](https://community.developer.atlassian.com/t/check-if-child-page-already-exists-using-confluence-rest-api-javascript/53718 "2021-11-16T16:34:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurence](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@Laurence](https://community.developer.atlassian.com/u/Laurence)\
**Post date:** [November 16, 2021, 4:34pm UTC](https://community.developer.atlassian.com/t/check-if-child-page-already-exists-using-confluence-rest-api-javascript/53718/1 "2021-11-16T16:34:47Z")

</div>

Currently I have an HTML button macro that makes a POST request with Fetch to create a new child page. The issue is that I have to delete the child page each time before creating it again. I would like to be able to check if the child page already exists (by page title I suppose) and to either make a PUT request to update the page with new information or to just DELETE it and create a new page.

Below is my pageExists function, the issue is that I’m not able to see the child pages in the response. The idea is to loop through the child pages and find a single child page which has a certain title, if that page exists then return true, if not return false.

```auto
let pageExists = function (parentId) {
    let myUrl = `http://svapptest:8090/confluence/rest/api/content/${parentId}/child`

    fetch(myUrl, {
        method: 'GET',
        headers: {
            'Accept': 'application/json'
        }
    }).then(response => response.json())
        .then(data => console.log(data))
}

```

Right now the response I get is:  
 ![child-return-value](https://global.discourse-cdn.com/atlassiandeveloper/original/3X/d/8/d84662150e4d5cca09cd736503c4a32774132428.png)

I also get this response when adding /descendant in place of /child to the end of the URL.

---

<div class="post-metadata">

**Author:** ![adam.labus](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/adam.labus/32/39809_2.png) [@adam.labus](https://community.developer.atlassian.com/u/adam.labus)\
**Post date:** [November 16, 2021, 5:39pm UTC](https://community.developer.atlassian.com/t/check-if-child-page-already-exists-using-confluence-rest-api-javascript/53718/2 "2021-11-16T17:39:56Z")

</div>

Hi @Laurence

change:

```auto
let myUrl = `http://svapptest:8090/confluence/rest/api/content/${parentId}/child`

```

to

```auto
let myUrl = `http://svapptest:8090/confluence/rest/api/content/${parentId}/child?expand=page`

```

doc → [https://docs.atlassian.com/ConfluenceServer/rest/7.14.0/#api/content/{id}/child-children](https://docs.atlassian.com/ConfluenceServer/rest/7.14.0/#api/content/%7Bid%7D/child-children)

or

```auto
let myUrl = `http://svapptest:8090/confluence/rest/api/content/${parentId}/child/page`

```

doc → [https://docs.atlassian.com/ConfluenceServer/rest/7.14.0/#api/content/{id}/child-childrenOfType](https://docs.atlassian.com/ConfluenceServer/rest/7.14.0/#api/content/%7Bid%7D/child-childrenOfType)

BTW - the page title is unique in space, you can find page by title in the space using this API

```auto
let url = "http://localhost:1990/confluence/rest/api/content?title=Test page&spaceKey=AAA"
let username = "admin"
let password = "admin"

fetch(url, {
    method: "GET",
    headers: {
        "Authorization": "Basic " + btoa(username + ":" + password), 
        "Content-Type": "application/json"
    }
})
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

```

Cheers  
Adam

---

<div class="post-metadata">

**Author:** ![Laurence](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@Laurence](https://community.developer.atlassian.com/u/Laurence)\
**Post date:** [November 16, 2021, 7:21pm UTC](https://community.developer.atlassian.com/t/check-if-child-page-already-exists-using-confluence-rest-api-javascript/53718/3 "2021-11-16T19:21:26Z")

</div>

Thank you! It’s working now
