JSONAPI PATCH Basket returns err 500 - Invalid JSON in body
Posted: 17 Apr 2018, 14:46
Hello,
I tried to patch a basket with the JSONAPI as described in https://aimeos.org/docs/Developers/Clie ... age_basket and it was not working (returning error 500 - Invalid JSON in body).
I needed to add some small changes to make it work.
I share it with you.
Can you confirm that what I made is correct?
had to be changed to :
and
to pass the test in ai-client-jsonapi/client/jsonapi/src/Client/JsonApi/Basket/Standard.php (L136)
At that point the new customerid was still not returned in the response.
in ai-client-jsonapi/client/jsonapi/src/Client/JsonApi/Basket/Standard.php (L142)
had to be added to return the basket with the new customerid.
Is this correct?
Note : I don't know how to update the status.
Thank you a lot,
sbn
I tried to patch a basket with the JSONAPI as described in https://aimeos.org/docs/Developers/Clie ... age_basket and it was not working (returning error 500 - Invalid JSON in body).
I needed to add some small changes to make it work.
I share it with you.
Can you confirm that what I made is correct?
Code: Select all
var data = {data: [{
attributes: {
"order.base.customerid": response[0]['id'], // from customer response (optional)
"order.base.status": 1, // optional
"order.base.comment": "test" // (optional)
}
}]};
var url = response.links.self.href; // from basket response
if(response['meta']['csrf']) { // add CSRF token if available and therefore required
var csrf = {};
csrf[response['meta']['csrf']['name']] = response['meta']['csrf']['value'];
url += (url.indexOf('?') === -1 ? '?' : '&') + $.param(csrf);
}
$.ajax({
url: url, // returned from OPTIONS request
method: "PATCH",
dataType: "json",
data: data
}).done( function( result ) {
console.log( result.data );
});
Code: Select all
var data = {data: {
attributes: {
"order.base.customerid": response[0]['id'], // from customer response (optional)
"order.base.status": 1, // optional
"order.base.comment": "test" // (optional)
}
}};
and
Code: Select all
data: JSON.stringify(data)
to pass the test in ai-client-jsonapi/client/jsonapi/src/Client/JsonApi/Basket/Standard.php (L136)
Code: Select all
if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data->attributes ) )
in ai-client-jsonapi/client/jsonapi/src/Client/JsonApi/Basket/Standard.php (L142)
Code: Select all
if( isset( $payload->data->attributes->{'order.base.customerid'} ) ) {
$basket->setCustomerId( $payload->data->attributes->{'order.base.customerid'} );
}
Is this correct?
Note : I don't know how to update the status.
Thank you a lot,
sbn