Archeiving SKUs via that API does not work

I have been trying to use the api to mark a SKU as _archived.

The documentation says this property exists [Webflow CMS API Reference](http://SKU Model)

when I make a call to PATCH /sites/:site_id/products/:product_id/skus/:sku_id

it returns successful, but doesn’t change the value of the field (other fields such as name work).

Is this possible? Or is there another way I am supposed to mark a SKU as unavailable? I don’t want to delete it, because it may become available again.

I am able to change this field for items in the Product collection model.

@Robson - are you sending:

"_archived": true,

Through with your patch in the body of the request?

yes, but I also have to include the existing values for ‘sku-values’

Example: If I do the following

curl 'https://api.webflow.com/sites/xxxxxxxx/products/xxxxxxx/skus/xxxxxxx' \
  -H "Authorization: Bearer xxxxxxxxxxxxx" \
  -H 'accept-version: 1.0.0' \
  -H "Content-Type: application/json" \
  -X PATCH \
  --data-binary $'{
        "fields": {
          "_archived": true
        }
      }'

I will get the following error (I have no idea why this is either?):

{"msg":"Variant \"undefined\" is missing option \"Color\" for product \"Thing2\".","code":409,"name":"Conflict","path":"/sites/xxxxxx/products/xxxxx/skus/xxxxxx","err":"Conflict: Variant \"undefined\" is missing option \"Color\" for product \"Thing2\"."}

if I add the existing sku-values

curl 'https://api.webflow.com/sites/xxxxxxx/products/xxxxxx/skus/xxxxxx' \
  -H "Authorization: Bearer xxxxxxxxx" \
  -H 'accept-version: 1.0.0' \
  -H "Content-Type: application/json" \
  -X PATCH \
  --data-binary $'{
        "fields": {
          "sku-values": {
            "yyyyyyyyyy": "zzzzzzzzzzz"
          },
          "_archived": true
        }
      }'

i will get a successful response… but the archived property will be unchanged:

{“price”:{“value”:120,“unit”:“USD”},“_archived”:false,“_draft”:false,“sku-values”:{“yyyyyyyyyy”:“zzzzzzzzz”},“download-files”:,“name”:“Cloak Of Invisibility Color: Smoke Grey”,“slug”:“cloak-of-invisibility-color-smoke-grey”,“product”:“xxxxxxxxxxx”,“updated-on”:“2020-09-29T17:49:29.131Z”,“updated-by”:“xxxxxxxxxxx”,“created-on”:“2020-09-29T17:43:20.894Z”,“created-by”:“xxxxxxxxx”,“published-on”:null,“published-by”:null,“_cid”:“xxxxxxxxx”,“_id”:“xxxxxxxxx”}

@Robson - hmm, that is odd. I don’t have an ecommerce store to test with, so I’m not sure I can help much from here. Have you tried not wrapping in the fields object? Just something like

--data-binary $'{"_archived": true}'

I’m just wondering if it’s a nesting issue since it seems like it’s wanting to modify a variant rather than the sku.

No dice

"msg":"Request is malformed: Body should have required property 'fields'","code":400,"name":"BadRequestError"

@Robson - welp, that wasn’t it :slight_smile: haha, umm anyone with API experience have any thoughts? @webdev @QA_Brandon

It turns out I was incorrect below! There is not a bug in the Webflow API (at least not here!).

Some fields in SKUs are inherited from the parent the Product, or are generated automatically, and cannot be changed via the SKU endpoints. _archived seems to be one of those fields. There’s not a clear line between what’s an editable SKU field and what must be edited on the Product…but there ya go.

The specific error message (with a 409 Conflict status) happens when the PATCH request is missing the SKU’s sku-values field. In order to update fields in the SKU via the API, you have to include the SKU’s sku-values in the fields object.


Update 2021-01-19 - The following info is incorrect! After emailing Webflow support, they set me straight.

I just encountered this bug and opened a support ticket. It appears to be a problem with updating SKUs which are a part of a set of Variants.

Steps to re-create:

  1. Create a new Product without any variants/option sets and copy its ID
  2. Query that product to get its SKU:
    curl 'https://api.webflow.com/sites/{site id}/products/{product id}' \
    -H 'Authorization: Bearer {whatever your token is}' \
    -H 'accept-version: 1.0.0' \
    -H 'content-type: application/json' | python -m json.tool 
    
  3. Get the SKU ID from the response and send your PATCH request:
    curl 'https://api.webflow.com/sites/{site ID}/products/{product ID}/skus/{SKU ID}' \
    -X PATCH \
    -H 'Authorization: Bearer {your token}' \
    -H 'accept-version: 1.0.0' \
    -H 'content-type: application/json' \
    --data-binary $'{"fields": { "download-files": [{"name": "hey", "url": "https://hey.hey/hey.pdf"}]}}' | python -m json.tool
    
    (You can see I edited the Download Files field here.)
  4. You should get a 200 with the updated SKU in your response. (You can double-check the values you changed in the editor/designer, to be sure.)

On the same product, create at least one Option Set and repeat the process above. You’ll get the error mentioned by OP:

{
    "msg": "Variant \"undefined\" is missing option \"Variant\" for product \"{Your product name}\".",
    "code": 409,
    "name": "Conflict",
    "path": "/sites/{site ID}/products/{product ID}/skus/{SKU ID}",
    "err": "Conflict: Variant \"undefined\" is missing option \"Variant\" for product \"{Your product name}\"."
}

If you delete the option sets and try the PATCH request again, it should work. (At least, it did for me!)