1

Following is my code and struct for creating shopify articles. I never had a issue with them until recently where some of the pages get created and others send a 422 Unprocessable Entity response. can someone help me sorting this out as i dont see an issue here..!

pageArticle := &ArticleRequest{
                Article: Article{
                    Title:       FinalTitle,
                    Author:      "Hit Parader",
                    Tags:        Tags,
                    BodyHTML:    html,
                    PublishedAt: time.Now().UTC().Format("2006-01-02T15:04:05-0700"),
                    Image: ArticleImage{
                        Src: pageSRC,
                        Alt: title,
                    },
                    Metafields: []ArticleMeta{
                        {
                            Key:       "feature_image_page_number",
                            Value:     page,
                            Type:      "number_integer",
                            Namespace: "custom",
                        },
                    },
                },
            }

        spew.Dump(pageArticle)
        articleJSON2, err := json.Marshal(pageArticle)
        if err != nil {
            fmt.Println(err)
        }
        articleReq2, err := http.NewRequest("POST", newArticleQueryFinal, bytes.NewBuffer(articleJSON2))
        if err != nil {
            fmt.Println(err)
        }
        articleReq2.Header.Add("X-Shopify-Access-Token", token)
        articleReq2.Header.Add("Content-Type", "application/json")

        resp3, err := client.Do(articleReq2)
        if err != nil {
            fmt.Println(err)
        }

Struct

type ArticleRequest struct {
    Article Article `json:"article"`
}
type Article struct {
    Title       string        `json:"title"`
    Author      string        `json:"author"`
    Tags        string        `json:"tags"`
    BodyHTML    string        `json:"body_html"`
    PublishedAt string        `json:"published_at"`
    Image       ArticleImage  `json:"image"`
    Metafields  []ArticleMeta `json:"metafields"`
}
type ArticleImage struct {
    Src string `json:"src,omitempty"`
    Alt string `json:"alt,omitempty"`
}
type ArticleMeta struct {
    Key       string `json:"key"`
    Value     int    `json:"value"`
    Type      string `json:"type"`
    Namespace string `json:"namespace"`
}

same kind of content gives 2 response types. Im at a loss here.

enter image description here

enter image description here

Any help would be appreciated..!!!

Sp3LLingzz
  • 303
  • 1
  • 3
  • 14
  • 422 is an HTTP response code, don't stop there; you should read and decode/unmarshal the response's body, it is quite likely that it will contain an more detailed API-specific error message regarding the invalid input. – mkopriva Jan 08 '23 at 05:21
  • Image upload failed. Image https:\/\/archive.org\/download\/hitparadermagazi37unse_0\/page\/cover failed to download. - timeout reached. Make sure file can be downloaded successfully. Now how can i make sure the image from internet archive gets downloaded? – Sp3LLingzz Jan 08 '23 at 09:57

0 Answers0