documentation-developer
documentation-developer copied to clipboard
IBX-8947: Add 2 cart REST routes; update Cart examples
| Question | Answer |
|---|---|
| JIRA Ticket | IBX-8947 |
| Versions | 4.6, master |
| Edition | All |
Add two routes:
/api/ibexa/v2/cart/{identifier}/validateadded in ibexa/cart#38 (and asked in IBX-8947)/api/ibexa/v2/cart/authorizeadded in ibexa/cart#80
Add XML examples and update JSON examples.
Examples generation
Done with
- Commerce 4.6.11
- DDEV
- ibexa/cart#97
set -x;
host='http://ddev-ibexa-tmp.ddev.site:8080';
baseUri="$host/api/ibexa/v2";
mimeTypePrefix='application/vnd.ibexa.api';
restRefDir='docs/api/rest_api/rest_api_reference';
for format in 'json' 'xml'; do
parser='jq';
if [ 'xml' = "$format" ]; then
parser='xq';
fi;
curl "$baseUri/cart/authorize" \
-c anonymous_cookies.txt \
-X 'POST' \
-H "Accept: $mimeTypePrefix.Token+$format" \
> $restRefDir/input/examples/cart/authorize/Token.$format.example;
anonymous_token=`cat $restRefDir/input/examples/cart/authorize/Token.$format.example | $parser -r '.Token.value'`;
if [ 'json' = "$format" ]; then
echo '' >> $restRefDir/input/examples/cart/authorize/Token.$format.example;
fi;
curl "$baseUri/cart" \
-b anonymous_cookies.txt -H "X-CSRF-Token: $anonymous_token" \
-H "Content-Type: $mimeTypePrefix.CartCreate+$format" \
--data "@$restRefDir/input/examples/cart/POST/CartCreate.$format.example" \
-H "Accept: application/$format" \
> $restRefDir/input/examples/cart/POST/Cart.$format.example;
identifier=`cat $restRefDir/input/examples/cart/POST/Cart.$format.example | $parser -r '.Cart.identifier'`;
if [ 'json' = "$format" ]; then
echo '' >> $restRefDir/input/examples/cart/POST/Cart.$format.example;
fi;
curl "$baseUri/cart/$identifier" \
-b anonymous_cookies.txt -H "X-CSRF-Token: $anonymous_token" \
-H "Accept: $mimeTypePrefix.Cart+$format" \
> $restRefDir/input/examples/cart/identifier/Cart.$format.example;
if [ 'json' = "$format" ]; then
echo '' >> $restRefDir/input/examples/cart/identifier/Cart.$format.example;
fi;
if [ '' = "$(diff $restRefDir/input/examples/cart/POST/Cart.$format.example $restRefDir/input/examples/cart/identifier/Cart.$format.example)" ]; then
rm $restRefDir/input/examples/cart/identifier/Cart.$format.example;
fi;
curl "$baseUri/cart/view" \
-b anonymous_cookies.txt -H "X-CSRF-Token: $anonymous_token" \
--data "@$restRefDir/input/examples/cart/view/CartViewInput.$format.example" \
-H "Content-Type: $mimeTypePrefix.CartViewInput+$format" \
-H "Accept: $mimeTypePrefix.CartView+$format" \
> $restRefDir/input/examples/cart/view/CartView.$format.example;
if [ 'json' = "$format" ]; then
echo '' >> $restRefDir/input/examples/cart/view/CartView.$format.example;
fi;
curl "$baseUri/cart/$identifier/validate" \
-b anonymous_cookies.txt -H "X-CSRF-Token: $anonymous_token" \
-X 'POST' \
-H "Accept: $mimeTypePrefix.CartConstraintViolationList+$format" \
> $restRefDir/input/examples/cart/identifier/validate/CartConstraintViolationList.$format.example;
if [ 'json' = "$format" ]; then
echo '' >> $restRefDir/input/examples/cart/identifier/validate/CartConstraintViolationList.$format.example;
fi;
curl "$baseUri/cart/$identifier" \
-b anonymous_cookies.txt -H "X-CSRF-Token: $anonymous_token" \
-X 'DELETE' \
;
rm anonymous_cookies.txt;
done;
exit 0;
Checklist
- [ ] Text renders correctly
- [ ] Text has been checked with vale
- [ ] Description metadata is up to date
- [ ] Redirects cover removed/moved pages
- [ ] Code samples are working
- [ ] PHP code samples have been fixed with PHP CS fixer
- [ ] Added link to this PR in relevant JIRA ticket or code PR