Problem adding labels to page via forge

Hi, I am writing forge app that creates a few Confluence Pages when a Jira Issue is created within a certain Project. After creating a page I want to add a label to that page via the REST API Endpoint:
“POST /wiki/rest/api/content/{id}/label”
For that I used the code in the documentation:

After creating the confluence page I call that method with the page id I just received. However while the creation of the pages works without a problem, the labels simply arent there. The response json for the addLabel request is empty too:

{ results: , start: 0, limit: 200, size: 0 }

What am I doing wrong?
If any more information is needed I will provide that ASAP

Hello @michaelklement

Sending a request directly to the Add labels to content endpoint is working just fine for me.

I suggest you use a REST API test tool like Postman to check if the direct method works for you and your Confluence instance, as your Forge based request appears properly constructed.

PS. You can actually add the labels to the page at the same time as you create that page via the Create content endpoint, by specifying the labels as metadata:

{
    "space": {
        "key": "TS"
    },
    "type": "page",
    "title": "My new page",
    "metadata": {
        "labels": [
            {
                 "name":"label_1"
             },
            {
                "name":"label_2"
            }
        ]
    }
}

This method at least saves you having to make two separate calls to the REST API.

1 Like

Hello @sunnyape !
Thank you for your quick response.

I tried adding in the labels in metadata during page creation:

image

The page will still be created just fine, however the label is not there. When I try to execute the request for adding a label manually via REST I receive a 403 Forbidden.

The created page has no restrictions. When I manually try to add a label to the page theres no problem either. Any other Idea what im doing wrong?

Thanks already :slight_smile:

That’s a weird problem. If you are using the same credentials / token to do it manually via the web UI as via the REST API, then it should just work. I would try a different person’s credentials / token to see if it makes any difference. Check all the site permissions related to content and labels etc.
Apart from that, I can’t think of much else, as it sounds like a permission problem.

I agree that its a very strange problem. I had a look into the space permissions and gave myself and my app every permission but that didn’t solve the problem either. I tried manually executing the addLabel restcall with a different admin user and that also resulted in a 403 error.