提问者:小点点

shopify api在一次调用中发布多个变体图像


我试图通过api一次发布多个图像/变体到shopify。我目前正在使用guzzle php,它可以:

  $response = $shop->api()->rest('POST', '/admin/products/#{productnumber}/images.json' ,[
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ]

但是我需要做多个,所以我试着做这样的事情:

 $response = $shop->api()->rest('POST', '/admin/products/#{productnumber}/images.json' ,[
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ],
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ]

上述方法不起作用。这也不起作用:

 $response = $shop->api()->rest('POST', '/admin/products/#{productnumber}/images.json' ,[
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"],
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ]

我可以循环每个图像和变体,但我试图避免多次调用。请让我知道。谢谢你!


共1个答案

匿名用户

我认为您必须使用GraphQL并尝试在那里添加一个图像数组。RestAPI是一种单技巧的小马,似乎每幅图像一次呼叫。我浏览了所有的旧代码,总是在每张图像上烧掉一个API调用。

GraphQL有图像[]的概念,所以这似乎是你最好的选择。