Creating new article with the same content gives errors

Creating new article with the same content gives errors

ashensha
Visitor
1 0 0

Hi 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.

ashensha_0-1673154537081.png

 

ashensha_1-1673154562907.png

 

 

Any help would be appreciated..!!!

Replies 0 (0)