question

yekta1 avatar image
yekta1 asked Erick Ramirez commented

Astra Delete API doesn't work when you pass more than one column

I have a table like this:

CREATE TABLE test.comments_by_users (
        username  text,
        comment_id  timeuuid,
        PRIMARY KEY (username, comment_id)
);

I'm trying to use Astra Rest API to delete a user comment by passing username and comment_id and it won't work. here's the request I send, it returns 204 HTTP codes but it does not delete anything.

curl -X 'DELETE' \
  'https://apps.astra.datastax.com/api/rest/v2/keyspaces/test/comments_by_user/test%2Ced8caf30-9d74-11ec-8569-7587bb715ab1' \
  -H 'accept: application/json' \
  -H 'X-Cassandra-Token: xxxx'

when I pass only the username it works, but that way it removes all of the user's comments.

astra dbstargate
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

There's an error in the way that you've formatted the URL in your HTTP request.

When you have a compound primary key in your table, you need to use the forward slash (/) to separate them. In your case where the PRIMARY KEY is:

    PRIMARY KEY (username, comment_id)

the string format is:

    username/comment_id

Here's an example API call where the forward slash is URL encoded (%2F):

    /api/rest/v2/keyspaces/community/comments_by_users/corazon%2F5f6b3110-9db3-11ec-95d9-a7723ae72079

Note that you've used a comma (URL encoded as %2C) instead of forward slash.

For future reference, we've provided a Swagger UI to help you figure out how to construct URLs for API calls to your database. The link to your Swagger UI can be found on the dashboard for your DB under the Connect tab:

c13511-swagger-ui.png


c13511-swagger-ui.png (384.0 KiB)
2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

hi, thanks for the answer, I did use Swagger UI for testing with username/comment_id format, but it didn't work for me, now after reading your answer I tested again and this time I noticed Swagger send the request like this username%2Fcomment_id, it replaces / with %2F.

I think it's a bug, you should fix it.

0 Likes 0 ·
We don't "own" Swagger UI. We just use it. Cheers!
0 Likes 0 ·
jeffdavies avatar image
jeffdavies answered

Hi Yetka1,

I saw the same issues when using the Swagger UI. However, when I pasted the same code directly into the bash shell on my mac, it did delete the record:

curl -X 'DELETE' \
  'https://REDACTED-us-east-2.apps.astra.datastax.com/api/rest/v2/keyspaces/demo/comments_by_users/test/ed8caf30-9d74-11ec-8569-7587bb715ab1' \
  -H 'accept: application/json' \
  -H 'X-Cassandra-Token: AstraCS:REDACTED'

Notice that the URL portion of the primary key does not use URL escape codes. The Swagger UI introduces the escape code %2F. It is this escape code that causes the problems. I agree this is an issue with Swagger, but I'm not sure who to ping on this. At least there is a path forward!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.