cancel
Showing results for 
Search instead for 
Did you mean: 

How to reassign a category using REST API

SOLVED

How to reassign a category using REST API

I use Magento 2.3.2

I have two categories (ids:760, 761) assigned to "Default Category" (id:2)

{
    "id": 2,
    "parent_id": 1,
    "name": "Default Category",
    "is_active": true,
    "position": 1,
    "level": 1,
    "children": "760,761",
    "path": "1/2",
	...
}

{
    "id": 760,
    "parent_id": 2,
    "name": "Main Category",
    "is_active": true,
    "position": 0,
    "level": 2,
    "path": "1/2/760",
	...
}


{
    "id": 761,
    "parent_id": 2,
    "name": "Should be a Sub Category",
    "is_active": true,
    "position": 0,
    "level": 2,
    "path": "1/2/761",
	...
}

Now I need to reassign 761 as a subcategory of 760.
I use postman PUT command to endpoint

PUT  https://myURL/index.php/rest/V1/categories/761

with following body

 

{
    "category": {
    	       "id":761,
		"parent_id": 760,
		"level": 3,
		"name": "Should be a Sub Category, so do it",
	        "is_active": false,
	        "position": 1
	},
	"saveOptions": true
}

Even if I have changed name, is_active or position, I am not able change parent_id any way. I receive back again (with no errors, status:200)

{
    "id": 761,
    "parent_id": 2,
    "name": "Should be a Sub Category, so do it",
    "is_active": false,
    "position": 1,
    "level": 2,
    "path": "1/2/761",
	...
}

I have tried also to use POST command on

POST  https://myURL/index.php/rest/V1/categories

I have tried set/notset  path, levels etc but without any progress.

When I omit ID

{
    "category": {
	"parent_id": 760,
	"level": 3,
	"name": "Should be a Sub Category, so do it",
	"is_active": false,
	"position": 1
     },
     "saveOptions": true
}

it works OK, and I receive a new category (id:1118) assigned to 760.

{
    "id": 1118,
    "parent_id": 760,
    "name": "Should be a Sub Category, so do it",
    "is_active": false,
    "position": 1,
    "level": 3,
    "children": "",
    ....
}

I have used SOAP API to rearrange categories in Magento 1.9 without any problems.
So am I missing some importent detail, or is it simply forbidden?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to reassign a category using REST API

Hello @sorrex 

Please use following PUT command endpoint to set parent_id of any category.

 

https://devdocs.magento.com/swagger/#/catalogCategoryManagementV1/catalogCategoryManagementV1MovePut

 

Hope it helps.

 

 

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

View solution in original post

1 REPLY 1

Re: How to reassign a category using REST API

Hello @sorrex 

Please use following PUT command endpoint to set parent_id of any category.

 

https://devdocs.magento.com/swagger/#/catalogCategoryManagementV1/catalogCategoryManagementV1MovePut

 

Hope it helps.

 

 

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"