plone.restapi
plone.restapi copied to clipboard
RESTAPI with ++api++ path returns wrong @id
The RESTAPI, when called on a backend with a ++api++ (like for instance in https://6.demo.plone.org/++api++/
) returns a wrong @id
(i.e. without the ++api++
path).
Is this the intended behaviour?
To reproduce it
On https://6-classic.demo.plone.org
the behaviour is as expected
SITE_URL=https://6-classic.demo.plone.org
USER=manager:plonemanager
TYPE_TITLE="mytype"
TYPE_AT_ID=$( \
curl \
-s -X POST ${SITE_URL}/@controlpanels/dexterity-types \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"title": '\""${TYPE_TITLE}"\"'}' \
--user ${USER} \
| jq -r '."@id"' \
)
echo "${TYPE_AT_ID}"
# -> https://6-classic.demo.plone.org/@controlpanels/dexterity-types/mytype
With the returned @id
one could e.g. delete the created type:
curl \
-i -X DELETE "${TYPE_AT_ID}" \
-H "Accept: application/json" \
--user ${USER}
But when calling the RESTAPI
on a "backend" via the ++api++
path (e.g. https://6.demo.plone.org/++api++/
). The returned @id
points to a url without ++api++
in the path.
SITE_URL=https://6.demo.plone.org/++api++
USER=admin:admin
TYPE_TITLE="mytype"
TYPE_AT_ID=$( \
curl \
-s -X POST ${SITE_URL}/@controlpanels/dexterity-types \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"title": '\""${TYPE_TITLE}"\"'}' \
--user ${USER} \
| jq -r '."@id"' \
)
echo "${TYPE_AT_ID}"
# -> https://6.demo.plone.org/@controlpanels/dexterity-types/mytype
The returned @id
is at https://6.demo.plone.org
which is not the same as the requesting url https://6.demo.plone.org/++api++
(note the missing ++api++
path).
Calls based on the returned wrong @id
will fail, e.g. the following
# the following fails because wrong @id
curl \
-i -X DELETE "${TYPE_AT_ID}" \
-H "Accept: application/json" \
--user ${USER}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot DELETE /@controlpanels/dexterity-types/mytype</pre>
</body>
</html>
Here is for instance necessary to first get the type id:
TYPE_ID=$( \
curl \
-s -X GET ${SITE_URL}/@controlpanels/dexterity-types \
-H "Accept: application/json" \
--user ${USER} \
| jq -r --arg type_at_id "${TYPE_AT_ID}" '.items[] | select(."@id"==$type_at_id) | .id' \
)
echo ${TYPE_ID}
curl \
-i -X DELETE "${SITE_URL}/@controlpanels/dexterity-types/${TYPE_ID}" \
-H "Accept: application/json" \
--user ${USER}