英文:
HTTP PUT call error to shopify when sending array in json request for metadata list type
问题
这是一个用于更新Shopify中现有文章的元字段的HTTP PUT响应。
func UploadArticleListImg(client *http.Client, ArticleIDs []string, imageURL []string, blogID string) {
newArticleQueryFinal := fmt.Sprintf(newArticleQuery, blogID)
for _, ID := range ArticleIDs {
Article := &ArticlePut{
Blog_id: blogID,
ID: ID,
Metafields: []ArticlePutMeta{
{
Key: "flip_book_images",
Value: imageURL,
Type: "list.url",
Namespace: "custom",
},
},
}
spew.Dump(Article)
articleJSON, err := json.Marshal(map[string]interface{}{"Article": Article})
articleReq, err := http.NewRequest("PUT", newArticleQueryFinal, bytes.NewReader(articleJSON))
articleReq.Header.Add("X-Shopify-Access-Token", token)
articleReq.Header.Add("Content-Type", "application/json")
resp, err := client.Do(articleReq)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp.Status)
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
sb := string(body)
fmt.Println(sb)
}
}
我的结构体如下:
type ArticlePut struct {
Blog_id string `json:"blog_id"`
ID string `json:"id"`
Metafields []ArticlePutMeta `json:"metafields"`
}
type ArticlePutMeta struct {
Key string `json:"key"`
Value []string `json:"value"`
Type string `json:"type"`
Namespace string `json:"namespace"`
}
我收到一个错误信息:
406 Not Acceptable
这是我的文章元字段定义。
这是关于list_url元数据类型的文档。
我在这里漏掉了什么?请帮忙解决。
英文:
This is an http PUT response to update the metafield of an existing article in shopify.
PUT API documentation on Articles
func UploadArticleListImg(client *http.Client, ArticleIDs []string, imageURL []string, blogID string) {
newArticleQueryFinal := fmt.Sprintf(newArticleQuery, blogID)
for _, ID := range ArticleIDs {
Article := &ArticlePut{
Blog_id: blogID,
ID: ID,
Metafields: []ArticlePutMeta{
{
Key: "flip_book_images",
Value: imageURL,
Type: "list.url",
Namespace: "custom",
},
},
}
spew.Dump(Article)
articleJSON, err := json.Marshal(map[string]interface{}{"Article": Article})
articleReq, err := http.NewRequest("PUT", newArticleQueryFinal, bytes.NewReader(articleJSON))
articleReq.Header.Add("X-Shopify-Access-Token", token)
articleReq.Header.Add("Content-Type", "application/json")
resp, err := client.Do(articleReq)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp.Status)
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
sb := string(body)
fmt.Println(sb)
}
}
my structs are like below
type ArticlePut struct {
Blog_id string `json:"blog_id"`
ID string `json:"id"`
Metafields []ArticlePutMeta `json:"metafields"`
}
type ArticlePutMeta struct {
Key string `json:"key"`
Value []string `json:"value"`
Type string `json:"type"`
Namespace string `json:"namespace"`
}
im getting an error saying
> 406 Not Acceptable
These are my Article metafield definitions.
and this is the documentation on the list_url metadata type
what am i missing here?? Please help.
答案1
得分: 1
如果我像下面这样输入metafield的值,它是有效的。
值:`["https://www.shopify.com","https://www.shopify.com","https://www.shopify.dev"]`
但是我不知道如何构建imageURL以使其在单引号中。
英文:
If I input the values for metafield like below it works.
Value: `["https://www.shopify.com","https://www.shopify.com","https://www.shopify.dev"]`
But I dont know how to construct the imageURL to have single quotes around
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论