1

Im using GOLANG to create a blog and its article following the article Create an article with an image, which will be downloaded by Shopify.

Following is my spew.dump for the API request and my response back. Im unable to get the image url. this was working fine couple of months ago. im using the 2022-07 API. I tried duplicating my theme also as some had suggested. but did not work. any help would be valuable.

This is my newarticle function

func newArticle(client *http.Client, Title string, Tags string, Body string, ImgSRC string, ImgTitle string, metaValue string, QueryURL string) *http.Response {
    pageArticle := &ArticleRequest{
        Article: Article{
            Title:       Title,
            Author:      "Hit Parader",
            Tags:        Tags,
            BodyHTML:    Body,
            PublishedAt: time.Now().UTC().Format("2006-01-02T15:04:05-0700"),
            Image: ArticleImage{
                Src: ImgSRC,
                Alt: ImgTitle,
            },
            Metafields: []ArticleMeta{
                {
                    Key:       "feature_image_page_number",
                    Value:     metaValue,
                    Type:      "single_line_text_field",
                    Namespace: "custom",
                },
            },
        },
    }

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

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

    body, err := io.ReadAll(resp3.Body)
    if err != nil {
        fmt.Println(err)
    }

    sb := string(body)
    fmt.Println(sb)

    return resp3
}

Spew.Dump

> (*load.ArticleRequest)(0xc000186000)({  Article: (load.Article) {
> Title: (string) (len=83) "Hit Parader Magazine - January/February 2008
> - Hard Rock's Top 100 Live Bands-cover",   Author: (string) (len=11) "Hit Parader",   Tags: (string) (len=130) "2000s, 2008, cover,
> hitparadermagazi51unse_32, Hit Parader Magazine - January/February
> 2008 - Hard Rock's Top 100 Live Bands-cover",   BodyHTML: (string)
> (len=92) "<H1>Hit Parader Magazine - January/February 2008 - Hard
> Rock's Top 100 Live Bands-cover</H1>",   PublishedAt: (string)
> (len=24) "2023-05-14T15:35:41+0000",   Image: (load.ArticleImage) {
> Src: (string) (len=71)
> "https://archive.org/download/hitparadermagazi51unse_32/page/cover_large",
> Alt: (string) (len=83) "Hit Parader Magazine - January/February 2008 -
> Hard Rock's Top 100 Live Bands-cover"   },   Metafields:
> ([]load.ArticleMeta) (len=1 cap=1) {    (load.ArticleMeta) {
>     Key: (string) (len=25) "feature_image_page_number",
>     Value: (string) (len=3) "1,2",
>     Type: (string) (len=22) "single_line_text_field",
>     Namespace: (string) (len=6) "custom"    }   }  } })

Response

{
  "article": {
    "id": 564313718976,
    "title": "Hit Parader Magazine - January/February 2008 - Hard Rock's Top 100 Live Bands-cover",
    "created_at": "2023-05-14T08:35:38-07:00",
    "body_html": "\u003ch1\u003eHit Parader Magazine - January/February 2008 - Hard Rock's Top 100 Live Bands-cover\u003c/h1\u003e",
    "blog_id": 84637483200,
    "author": "Hit Parader",
    "user_id": 77498417344,
    "published_at": "2023-05-14T08:35:38-07:00",
    "updated_at": "2023-05-14T08:35:38-07:00",
    "summary_html": null,
    "template_suffix": null,
    "handle": "hit-parader-magazine-january-february-2008-hard-rocks-top-100-live-bands-cover",
    "tags": "2000s, 2008, cover, Hit Parader Magazine - January/February 2008 - Hard Rock's Top 100 Live Bands-cover, hitparadermagazi51unse_32",
    "admin_graphql_api_id": "gid://shopify/OnlineStoreArticle/564313718976"
  }
}
Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
Sp3LLingzz
  • 303
  • 1
  • 3
  • 14
  • Please log and share the content of `articleJSON2` too. And have you tried another image URL (maybe `archive.org` blocks `shopify`). – Zeke Lu May 24 '23 at 04:47

0 Answers0