Scratching my head with this issue, and I just do not understand why this is happening in the first place. Made a custom REST API call to remove multiple items from the cart with one single API call from calling a similar REST API calls multiple time to prevent too much activity happening. I have the logged user cart working just fine, but somehow the guest cart is throwing me this error:
Class int[] does not exist
vendor\module\etc\webapi.xml
<!-- Works fine -->
<route url="/V1/custom/carts/mine/items/clear" method="PUT">
<service class="Vendor\Module\Api\CartItemRepositoryInterface" method="clearAsUser" />
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="cartId" force="true">%cart_id%</parameter>
</data>
</route>
<!-- Does not work -->
<route url="/V1/custom/guest-carts/:cartId/items/clear" method="PUT">
<service class="Vendor\Module\Api\CartItemRepositoryInterface" method="clearAsGuest" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
vendor\module\api\CartItemRepositoryInterface.php
/**
* Removes an array of items from the specified cart.
*
* @param int $cartId
* @param int[] $cartItems
* @return bool
*/
public function clearAsUser($cartId, $cartItems);
/**
* Removes an array of items from the specified cart.
*
* @param string $cartId
* @param int[] $cartItems
* @return bool
*/
public function clearAsGuest($cartId, $cartItems);
Request Data
{
"cartItems": [
0: 123456,
1: 789012
]
}
EDIT
vendor\module\model\CartItemRepository.php
/**
* @param \Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepo
* @param \Magento\Quote\Api\GuestCartItemRepositoryInterface $guestItemRepo
*/
public function __construct(
\Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepo,
\Magento\Quote\Api\GuestCartItemRepositoryInterface $guestItemRepo
){
$this->cartItemRepo = $cartItemRepo;
$this->guestItemRepo = $guestItemRepo;
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logging.log');
$this->logger = new \Zend\Log\Logger();
$this->logger->addWriter($writer);
}
/**
* {@inheritdoc}
*/
public function clearAsGuest($cartId, $cartItems)
{
$this->logger->info('clearAsGuest: ' . $cartId);
try{
foreach($cartItems as $itemId){
if(!$this->guestItemRepo->deleteById($cartId, $itemId)){
throw new \Exception('Some items were unable to be deleted from your cart.');
} else {
$this->logger->info('Removed! ' . $itemId);
}
}
return true;
} catch (\Exception $e){
$this->logger->info('Error: ' . $e->getMessage());
return false;
}
}
I've tried the guest cart api without the array to see if it does recognize the guest-cart id, and it does recognize it without an issue, but when I try to send the array of integers it will give me the error.

DO NOT use PHP7 scalar argument types or return types if you want to hook this into the REST API! Add PHPDoc annotations for all arguments and the return type to all methods! Use Fully Qualified Class Names in the PHPDoc block!` .You can find an idea from vinai post https://magento.stackexchange.com/a/160617/4564
– Amit Bera Jun 12 '18 at 14:00