Hello,
We're trying to use the Admin API 2020-10 to archive a number of older products. We're using the REST PUT requests documented here. The docs say there are 3 supported values: active, archived and draft. The example PUT request uses the "draft" status. However, when we run that request it never updates the status. The response comes back with HTTP 200 OK but the body of it still shows "status" : "active" and when checking the product in the catalog is is in fact active.
The release notes for 2020-10 also mention this feature so we expected it to function. Is the "archived" status actively supported in the Admin API 2020-10 REST interface? Are we missing something? Doing something wrong?
// request url
// https://<secret>:<value>@<domain>/admin/api/2020-10/products/4994767192197.json
// request body
{
"product": {
"id": 4994767192197,
"status": "archived"
}
}
// response body
{
"product": {
"id": 4994767192197,
// ...
"status": "active",
// ...
}
}
Thanks,
sfsdev
Screenshot of status docs
Screenshot of release notes
I tried setting the Product's "published_status" to "unpublished" but it didn't reflect that change. There isn't a "published_state" property for Products. The docs only mention "published_status" as a filter to the GET requests.
It's interesting that I can't adjust the "published_scope" to anything but "web" or "global." What if I want to unpublish it? In other words, what's the REST API's equivalent to the UI's dialog where you uncheck all Sales Channels for a Product and apply it?
Thanks,
sfsdev
Sorry that wasn't much help. Not something I've attempted before.
I assume you're using the REST API for this? Have you tried the GraphQL API productChangeStatus instead? I've not got around to using it much but I know you can do something like this in Node, for example. Just need to add your product ID, shop and access token.
let query = `mutation productChangeStatus($productId: ID!, $status: ProductStatus!) {
productChangeStatus(productId: $productId, status: 'archived') {
product {
id
}
userErrors {
code
field
message
}
}
}`;
async function graphql(query) {
const fetch = require("node-fetch");
let res = await fetch(`https://SHOP/admin/api/2020-10/graphql.json`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": ACCESS_TOKEN
},
body: JSON.stringify(query)
});
let final = await res.json();
return final;
}
Thanks for the example code. We're pretty far down the REST API path. We'll switch over to GraphQL if absolutely necessary. Just wish the REST API worked the way the documents say it's supposed to. Hopefully someone from Shopify will chime in and we're missing something simple.
Thanks Again,
sfsdev
I know it isn't the greatest solution but it's essentially the same amount of work involved as using the REST API here as it'll be just one request.
Yeah, I seem to run into a lot of issues and the support has been, quite honestly, shameful. So I'm trying to do my best to help out, even if it's not too useful, ha.
Once you setup the GQL, it seems strange to use Rest. I used think Rest was good enough for me too.
The main problem is, moving forward, I can see Rest getting left behind. Only GQL will be supported with the latest stuff. Amazingly though, there remain some things you can still only do with Rest, so there is that.
I think published status is a huge internal mess at the moment, hopefully, ironed out soon? I am playing in that same sandbox and nothing matches the docs for reality in a lot of places.
Thanks for your input. After minimal development I also feel that the community here, and Shopify, are leaning towards GraphQL over REST. The documentation seems thorough. I just wish it matched what the code actually does. Regardless, it's good to know I'm not going crazy and others are experiencing the same headaches.
Thanks Again,
sfsdev
@BoxUp & @HunkyBill,
Well I tried the GraphQL solution and, unfortunately, it doesn't work. The productChangeStatus mutation runs without issue. It just ignores the ARCHIVED status. Using GraphQL version 2020-10.
// https://<shop>.myshopify.com/admin/api/2021-01/graphql.json
// mutation
mutation productChangeStatus($productId: ID!, $status: ProductStatus!) {
productChangeStatus(productId: $productId, status: $status) {
product {
id
}
userErrors {
code
field
message
}
}
}
// variables
{
"productId": "gid://shopify/Product/<valid product id>",
"status": "ARCHIVED"
}
After that runs I lookup the same product id ...
// query
{
product(id: "gid://shopify/Product/<same product id>") {
title
description
status
}
}
// response
{
"data": {
"product": {
"title": ...
"description": ...
"status": "ACTIVE"
}
},
...
}
I also I tried the "DRAFT" status. That didn't stick. Switched to the 2021-01 candidate version of GraphQL. Still no go. Documented feature that straight up doesn't work.
It's awesome that these powerful APIs are available for Shopify stores and I'm excited to dig deeper. It's just so frustrating to chase a feature for two days that's supposed to work. <insert angry emoji here>
Frustrated,
sfsdev
User | Count |
---|---|
12 | |
11 | |
10 | |
8 | |
7 |