Closed jeroen-hso closed 3 years ago
Interesting - haven't come across that before.
Are you able to access the API endpoint(s) by accessing the API directly? e.g. via curl: rest/default/V1/products/some-product-with-a/-slash
I came across this article but it's ages old: https://magento.stackexchange.com/questions/142056/how-to-get-magento2-product-with-rest-if-sku-has-slash
I found the same issue on stackexchange.
This doesn't work:
public function getProduct($sku) { // $sku = '1234/56'
$result = $this->api('products')->show($sku);
if ($result->status() == 200) {
return $result->json();
}
And this works:
public function getProduct($sku) { // $sku = '1234/56'
$sku = urlencode($sku);
$result = $this->api('products')->show($sku);
if ($result->status() == 200) {
return $result->json();
}
@jeroen-hso ,
Are there any problems with URL encoding as the default on SKUs? I'm open to the idea if not :)
@ahinkle sorry for the late reply. I don't think there are any problems when the URL for SKU is default encoded. But I'm not a expert on this.
@ahinkle just found out one problem, when the SKU contains a space URL encoding changes the space to + (I don't understand why suppliers create SKU's with spaces)
https://stackoverflow.com/questions/5572718/php-convert-spaces-in-string-into-20 --> rawurlencode()
Yeah, good point. I think for now I'll keep the current implementation and leave it up to the users to pass it how they would like in their own applications. Just feels a bit finicky and could break some applications.
Hi Andy,
How to handle sku's with slashes (/)? Do I have to urlencode all the sku's before using an API endpoint or is there setting for this? Is the urlencoding only needed for the url or also for the Postdata?
Thanks!