0

Q1). On Magento store I updated the product using API but can not updated all the fields, few fields (i.e. 'name') were not updated using the API. Is there any API to update product name?

Q2). I have updated the product name from the store and then I downloaded the product using the download API. But I can't see the updated name after download, it is same as previous one. example:- Originally product name was 'shirt'. I updated the name to 'shirt blue' After downloading I can not get the name updated, it was still 'shirt'. But on the store the name was updated to 'shirt blue'. Is this any restriction from Magento? And is there any solution to get the updated name of the product?

1
  • Can you provide some code what you have tested? So I could be more precise with my answer to your needs
    – kekw
    Commented Feb 14, 2023 at 7:38

1 Answer 1

0

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.