HTTP PUT call error to shopify when sending array in json request for metadata list type

huangapple go评论121阅读模式
英文:

HTTP PUT call error to shopify when sending array in json request for metadata list type

问题

这是一个用于更新Shopify中现有文章的元字段的HTTP PUT响应。

PUT API文档关于文章

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

这是我的文章元字段定义。

HTTP PUT call error to shopify when sending array in json request for metadata list type

这是关于list_url元数据类型的文档。

HTTP PUT call error to shopify when sending array in json request for metadata list type

我在这里漏掉了什么?请帮忙解决。

英文:

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.

HTTP PUT call error to shopify when sending array in json request for metadata list type

and this is the documentation on the list_url metadata type

HTTP PUT call error to shopify when sending array in json request for metadata list 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

huangapple
  • 本文由 发表于 2022年12月5日 17:19:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/74685842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定