Set Website/Store Assignment via Magento 2 API

If you need to update the website a product is assigned to in Magento via the
REST API, you can do this fairly easily.

You can get the current websites assigned by running this query:

curl "https://www.mystore.co.uk/rest/all/V1/products/MY-PRODUCT-SKU" \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer [token]'

This will return a JSON payload. Within the payload you’ll find:

  "id": 5687,
"sku": "MY-PRODUCT-SKU",
"name": "My Product",
"attribute_set_id": 4,
"price": 9.99,
"status": 1,
"visibility": 4,
"type_id": "simple",
"created_at": "2024-03-07 13:45:29",
"updated_at": "2025-02-24 14:20:09",
"weight": 1,
"extension_attributes": {
"website_ids": [
1,
3
],
}

The key part you’re looking for there is website_ids within
extension_attributes which will give you the currently assigned website IDs.

To set this data, you can make a PUT request:

curl -X "PUT" "https://www.mystore.co.uk/rest/all/V1/products/MY-PRODUCT-SKU" \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer [token]' \
-d $'{
"product": {
"extension_attributes": {
"website_ids": [
1,
3,
14,
22
]
}
}
}'

Which will then set the product to be in the given websites.