I was hoping there where a well known workaround for this, but for now I solved it by writing plugins.
To get and put product, I plugged in before the get and save function in \Magento\Catalog\Api\ProductRepositoryInterface
<?php
namespace Vendor\Module\Plugin\Product;
class RestSkuFix
{
/**
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param string $sku
* @param bool $editMode
* @param int|null $storeId
* @param bool $forceReload
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return array
*/
public function beforeGet($productRepository, $sku, $editMode = false, $storeId = null, $forceReload = false)
{
$sku = urldecode($sku);
return [$sku, $editMode, $storeId, $forceReload];
}
/**
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param bool $saveOptions
* @return array
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function beforeSave($productRepository, \Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
{
$product->setSku(urldecode($product->getSku()));
}
}
And this I did only in rest webapi by registering the plugin in Vendor/Module/etc/webapi_rest/di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\ProductRepository">
<plugin name="ProductRepositoryRestSkuFix" type="\Vendor\Module\Plugin\Product\RestSkuFix" />
</type>
</config>
Now I can get and put product with slash by
get /rest/V1/products/100%252f1
and
put /rest/V1/products/100%252f1