Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTAPI with ++api++ path returns wrong @id #1542

Open
me-kell opened this issue Nov 23, 2022 · 0 comments
Open

RESTAPI with ++api++ path returns wrong @id #1542

me-kell opened this issue Nov 23, 2022 · 0 comments

Comments

@me-kell
Copy link

me-kell commented Nov 23, 2022

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}
@me-kell me-kell changed the title RESTAPE with ++api++ path returns wrong @id RESTAPI with ++api++ path returns wrong @id Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants