I only did async patches via API yet, but you only have to remove async
in url:
Also you have to request a token before, so magento understands you are authorized for desired action you want to complete. You can do this per Integration
via backend or simply for testing purpose via:
https://shopurl/rest/all/V1/integration/admin/token?username=YOURADMINACCOUNT&password=YOURADMINPASSWORD
API example endpoint to modify products:
https://shopurl/rest/async/V1/products/asynctest2
{
"product": {
"sku": "asynctest2",
"price": 10.00,
"name": "example name",
"custom_attributes": [
{
"attribute_code": "some_attribute",
"value": 2
}
]
}
}
You have to call the SKU of desired product in your API request url as well, like in my example it is asynctest2
As HTTP-Method you have to choose PUT
Below is an python3 example:
import requests
import json
url = "https://shopurl/rest/async/V1/products/asynctest2"
payload = json.dumps({
"product": {
"sku": "asynctest2",
"price": 10,
"name": "example name",
"custom_attributes": [
{
"attribute_code": "some_attribute",
"value": 2
}
]
}
})
headers = {
'Authorization': 'Bearer BEARERTOKENVALUE',
'Content-Type': 'application/json'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
Another way to do it via php
:
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://shopurl/rest/async/V1/products/asynctest2');
$request->setRequestMethod('PUT');
$body = new http\Message\Body;
$body->append('{
"product": {
"sku": "asynctest2",
"price": 10.00,
"name": "example name",
"custom_attributes": [
{
"attribute_code": "some_attribute",
"value": 2
}
]
}
}');
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
'Authorization' => 'Bearer BEARERTOKENVALUE',
'Content-Type' => 'application/json'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();