Create a page with labels

I’m trying to create a page with labels:
java code:

URL obj = new URL(urlCnfl + "/rest/api/content/");
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
conn.setRequestMethod("POST");
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes("UTF-8"));
conn.setRequestProperty ("Authorization", basicAuth);

def data='{'+
' "title": "title542764234534",'+
' "space": {'+
' "key": "SAUR"'+
'},'+
'"type": "page",'+
'"metadata": {'+
'"labels": ['+
'{'+
'"prefix": "global",'+
'"name": "label1"'+
'},'+
'{'+
' "prefix": "global",'+
' "name": "label2"'+
' }'+
' ]'+
' },'+
' "body": {'+
' "storage": {'+
' "value": "New page data",'+
' "representation": "storage"'+
' }'+
' }'+
'}';
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(data);
out.close();

json data from your example to create a page. The page is created, all data is correct, except for labels, they are not.
what’s the matter? Thank you!

How odd. Can we try to isolate the problem as Java-level or HTTP-level? Try running the following Bash script using HTTPie.

#!/usr/bin/env bash
PAYLOAD=$(cat <<EOF
{
    "title": "$(date +%s)",
    "type": "page",
    "space": {
        "key": "${SPACEKEY}"
    },
    "body": {
        "storage": {
            "value": "Hello world!",
            "representation": "storage"
        }
    },
    "metadata": {
        "labels": [
            {
                "prefix": "global",
                "name": "label1"
            },
            {
                "prefix": "global",
                "name": "label2"
            }
        ]            
    }
}
EOF
)

echo "${PAYLOAD}" | http -a ${CONFLUENCE_USERNAME}:${CONFLUENCE_PASSWORD} \
    POST ${CONFLUENCE_BASE_URL}/rest/api/content

It creates labels for me, but if it doesn’t work for you, then we’re on to something (I don’t know what yet). If it works, then we know there’s something in the Java-level.

Java-level.
In HTTP level i have another problem - CORS block. CORS plugin for the Grails did not help me :frowning: