cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.2.5 Deleting Releted Items Via REST API

SOLVED

Magento 2.2.5 Deleting Releted Items Via REST API

I need some help with figuring out how to delete releted items using the API interface.
Creating is simple

"product_links": [{
	"sku": "DIG1300",
	"link_type": "related",
	"linked_product_sku": "SABT4",
	"linked_product_type": "simple",
	"position": 0
}, {
	"sku": "DIG1300",
	"link_type": "related",
	"linked_product_sku": "   MC18",
	"linked_product_type": "simple",
	"position": 0
}],

etc.

I've tried setting some parameters with a null to no avail.

I'm hoping there's something similar to advanced pricing API where you can remove the option by setting qty to 0

working:

		"tier_prices": [{
			"customer_group_id": 4,
			"qty": 1,
			"value": 199,
			"extension_attributes": {
				"website_id": 0
			}
		}],

removed

		"tier_prices": [{
			"customer_group_id": 4,
			"qty": 0,
			"value": 199,
			"extension_attributes": {
				"website_id": 0
			}
		}],

Thank you.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Magento 2.2.5 Deleting Releted Items Via REST API

Hi @roman_polevecko

 

okay i understand your question , and yes you can remove that related products links via PUT method using rest api of Magento !

 

Below is the exact way/API details to remove this related products !

 

URL : http://mydomain.com/index.php/rest/V1/products/24-MB01/

 

Method : PUT

 

parameters : 

 

 

{  
   "product":{  
      "extensionAttributes":{  
         "category_links":[  
            {  
               "position":0,
               "category_id":"11"
            }
         ]
      },
      "sku":"24-MB01",
      "name":"Joust Duffle Bags",
      "price":10,
      "type_id":"simple",
      "status":1,
      "attribute_set_id":4,
      "product_links": [
       
    ]
   }
}

 

Authorization : bearer your-access-token 

 

So you just need to pass the blank array of product_links parameters like below  :

 

product_links": [
       
    ]

 

Update the product using above API details , it will remove the related products for the same !

 

I have tried the same in POSTMAN and it works perfectly 

 

Try at your end , Hope it helps !

 

 

if issue solved,Click Kudos & Accept as Solution

View solution in original post

Re: Magento 2.2.5 Deleting Releted Items Via REST API

Hi @roman_polevecko

 

 

Yes it is possible to remove single section as well !

 

you just need to remove specific items values from that product_links section !

 

Like below is the example !

 

"product_links": [
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB04",
            "linked_product_type": "simple",
            "position": 1
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB03",
            "linked_product_type": "simple",
            "position": 2
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB05",
            "linked_product_type": "simple",
            "position": 3
        },
        {
            "sku": "24-MB01",
            "link_type": "upsell",
            "linked_product_sku": "24-MB04",
            "linked_product_type": "simple",
            "position": 1
        },
        {
            "sku": "24-MB01",
            "link_type": "upsell",
            "linked_product_sku": "24-MB03",
            "linked_product_type": "simple",
            "position": 2
        },
        {
            "sku": "24-MB01",
            "link_type": "upsell",
            "linked_product_sku": "24-MB05",
            "linked_product_type": "simple",
            "position": 3
        }
    ]

From above parameters , if you wanted to remove upsell products , then you just need to remove upsell products entries from above parameters like below : 

 

"product_links": [
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB04",
            "linked_product_type": "simple",
            "position": 1
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB03",
            "linked_product_type": "simple",
            "position": 2
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB05",
            "linked_product_type": "simple",
            "position": 3
        }
    ]

Then same call PUT method with above given URL , it will remove upsell product separate section only !

 

it will remove specific section like only upsell products , its work on POSTMAN for the same !

  

Happy to help and keep helping others Smiley Happy 

if issue solved,Click Kudos & Accept as Solution

View solution in original post

5 REPLIES 5

Re: Magento 2.2.5 Deleting Releted Items Via REST API

Hi @roman_polevecko

 

So exactly , you would like to remove related products using API ? or you wanted to remove tier pricing using API ?

 

Could you please clarify , so its help us to troubleshoot the issue 

if issue solved,Click Kudos & Accept as Solution

Re: Magento 2.2.5 Deleting Releted Items Via REST API

I'm trying to remove "related products" via API.

the 'tier pricing' was just an example that works for removing 'tier pricing' entries. i was just hoping there's something similar to that for 'related products'.

Re: Magento 2.2.5 Deleting Releted Items Via REST API

Hi @roman_polevecko

 

okay i understand your question , and yes you can remove that related products links via PUT method using rest api of Magento !

 

Below is the exact way/API details to remove this related products !

 

URL : http://mydomain.com/index.php/rest/V1/products/24-MB01/

 

Method : PUT

 

parameters : 

 

 

{  
   "product":{  
      "extensionAttributes":{  
         "category_links":[  
            {  
               "position":0,
               "category_id":"11"
            }
         ]
      },
      "sku":"24-MB01",
      "name":"Joust Duffle Bags",
      "price":10,
      "type_id":"simple",
      "status":1,
      "attribute_set_id":4,
      "product_links": [
       
    ]
   }
}

 

Authorization : bearer your-access-token 

 

So you just need to pass the blank array of product_links parameters like below  :

 

product_links": [
       
    ]

 

Update the product using above API details , it will remove the related products for the same !

 

I have tried the same in POSTMAN and it works perfectly 

 

Try at your end , Hope it helps !

 

 

if issue solved,Click Kudos & Accept as Solution

Re: Magento 2.2.5 Deleting Releted Items Via REST API

Thank you so much! Works perfect! I was starting to lose it here. 95% through the integration and first trouble appears Smiley Very Happy

PS
Is it possible maybe to delete individual entries though?
It's not a big issue really, if not i can just save them before deleting and then repopulate with new data.

Re: Magento 2.2.5 Deleting Releted Items Via REST API

Hi @roman_polevecko

 

 

Yes it is possible to remove single section as well !

 

you just need to remove specific items values from that product_links section !

 

Like below is the example !

 

"product_links": [
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB04",
            "linked_product_type": "simple",
            "position": 1
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB03",
            "linked_product_type": "simple",
            "position": 2
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB05",
            "linked_product_type": "simple",
            "position": 3
        },
        {
            "sku": "24-MB01",
            "link_type": "upsell",
            "linked_product_sku": "24-MB04",
            "linked_product_type": "simple",
            "position": 1
        },
        {
            "sku": "24-MB01",
            "link_type": "upsell",
            "linked_product_sku": "24-MB03",
            "linked_product_type": "simple",
            "position": 2
        },
        {
            "sku": "24-MB01",
            "link_type": "upsell",
            "linked_product_sku": "24-MB05",
            "linked_product_type": "simple",
            "position": 3
        }
    ]

From above parameters , if you wanted to remove upsell products , then you just need to remove upsell products entries from above parameters like below : 

 

"product_links": [
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB04",
            "linked_product_type": "simple",
            "position": 1
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB03",
            "linked_product_type": "simple",
            "position": 2
        },
        {
            "sku": "24-MB01",
            "link_type": "related",
            "linked_product_sku": "24-MB05",
            "linked_product_type": "simple",
            "position": 3
        }
    ]

Then same call PUT method with above given URL , it will remove upsell product separate section only !

 

it will remove specific section like only upsell products , its work on POSTMAN for the same !

  

Happy to help and keep helping others Smiley Happy 

if issue solved,Click Kudos & Accept as Solution