使用管理API创建shopify产品

时间:2019-06-16 03:05:54

标签: php

我刚刚开始使用PHP编写一个小函数,以使用shopify创建admin API产品,但是每次都会出现错误

这是我得到的错误:

{"errors":{"order":["money field cannot be nil"]}}

这是我的PHP函数:

public function index() {
  $products_array = array(
      "product"=>array(
          'title'=>'',
          "title"=> "Burton Custom Freestlye 151",
          "body_html"=> "<strong>Good snowboard!</strong>",
          "vendor"=> "Burton",
          "order" => 1 ,
          "published"=> false
      ),
      "order" => array(
          'line_items' => array(
              array(
                  'variant_id' => 1136296753,
                  'quantity' => 1
              )
          )
      )
  );


  $url = "https://hidden-for-sec:hidden-forsec@me.myshopify.com/admin/api/2019-04/orders.json";

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_VERBOSE, 0);
  curl_setopt($curl, CURLOPT_HEADER, 1);
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($products_array));
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  $response = curl_exec ($curl);
  curl_close ($curl);
  echo "<pre>";
  print_r($response); }

0 个答案:

没有答案