aimeos / ai-client-jsonapi

Aimeos frontend JSON API
GNU Lesser General Public License v3.0
28 stars 6 forks source link

Clear Basket (self) Link #13

Closed exemplari closed 3 years ago

exemplari commented 3 years ago

My issue arose with trying to send a DELETE request to clear the basket.

First add some products with a POST to the product url . /jsonapi/basket?id=default&related=product { product data }

Store the response to my local basket model including the 'links' to modify the basket later.

Send a DELETE to the provided basket links.self.href , error bad JSON in response.

The issue I found was the basket self link provided by the first request was incorrect. Here is the link being provided by the Add Product basket response in links.self.href -> /jsonapi/basket?id=default&related=product

The correct link in side links.self.href should be /jsonapi/basket?id=default

"name": "aimeos/ai-client-jsonapi", "version": "2021.07.1",

aimeos commented 3 years ago

Can you please post the output that has been returned by the API?

exemplari commented 3 years ago
{
    "meta": {
        "total": 1,
        "prefix": null,
        "content-baseurl": "/aimeos",
        "csrf": {
            "name": "_token",
            "value": "i1oWnlC5qATlB2V9X0J0kgjOftMNniOhIr2j0ZK8"
        }

    },
    "links": {
        "self": {
            "href": "http://domain.com/jsonapi/basket?id=default&related=product",
            "allow": ["DELETE", "GET", "PATCH", "POST"]
        },
        "basket/product": {
            "href": "http://domain.com/jsonapi/basket?id=default&related=product",
            "allow": ["POST"]
        },
        "basket/service": {
            "href": "http://domain.com/jsonapi/basket?id=default&related=service",
            "allow": ["POST"]
        },
        "basket/address": {
            "href": "http://domain.com/jsonapi/basket?id=default&related=address",
            "allow": ["POST"]
        },
        "basket/coupon": {
            "href": "http://domain.com/jsonapi/basket?id=default&related=coupon",
            "allow": ["POST"]
        }

    },
aimeos commented 3 years ago

Thanks. What is the requested URL that returns that response?

exemplari commented 3 years ago

Post a product to http://domain.com/jsonapi/basket?id=default&related=product

aimeos commented 3 years ago

The self link is correct because you've sent a POST request to /jsonapi/basket?id=default&related=product

exemplari commented 3 years ago

I understand how that could make sense, but ....

  1. The allowed methods . DELETE is not allowed here . That is why i raise the issue originally.
  2. This return is not a Basket/Product , it is a Basket . In which case self would refer to /jsonapi/basket?id=default . Also now the Allowed methods would be true and DELETE valid.

But isn't this returning a Basket

aimeos commented 3 years ago

Good point. We've changed that in dev-master and 2021.07.x-dev. Can you give it a try?

exemplari commented 3 years ago

I just tried the -dev branch and it works as expected. The basket is dependably referenced with links.self. The documentation needs updating to match https://aimeos.org/docs/latest/frontend/jsonapi/basket-products/ . Also I see a data.links.self - perhaps this is the place where the request link should display.

"name": "aimeos/ai-client-jsonapi", "version": "2021.07.x-dev", "reference": "b2ec6fc312ccfd2da0791bca8f41db8c70ee0483"

aimeos commented 3 years ago

Thanks, fixed now in 2021.x docs.