title: PHP REST post with Shopify API
body: <p>I have a shopify store and would like to add approximately 200 orders using the Shopify API <a href="https://help.shopify.com/api/reference/order#create" rel="nofollow">https://help.shopify.com/api/reference/order#create</a></p>
  
  <p>I've never used PHP before but have put together the below script from previous questions and using the API example data and using a product from my store (variant_id).</p>
  
  <p>Unfortunately this is not placing an order with my store, but does return data for the last order placed with the store, despite not making a GET request. Would you say this is happening because of a syntax error, or am I just structuring the PHP incorrectly? Thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  $api_key = 'api-key here';
  $api_pass = 'api-password here';
  
  $api_url = 'https://' . $api_key . ':' . $api_pass . '@croft-watches.myshopify.com';
  
  $order_url = $api_url . '/admin/orders.json';
  
  $data_array = array("order" =&gt; array(
              "line_items" =&gt; array(
                  array(
                      "variant_id" =&gt; 10353765828,
                      "quantity" =&gt; 1
                  )
              ),
              "customer" =&gt; array(
                  "first_name" =&gt; "Paul",
                  "last_name" =&gt; "Norman",
                  "email" =&gt; "paul.norman@example.com"
              ),
              "billing_address" =&gt; array(
                  "first_name" =&gt; "John",
                  "last_name" =&gt; "Smith",
                  "address1" =&gt; "123 Fake Street",
                  "phone" =&gt; "555-555-5555",
                  "city" =&gt; "Fakecity",
                  "province" =&gt; "Ontario",
                  "country" =&gt; "Canada",
                  "zip" =&gt; "K2P 1L4"
              ),
              "shipping_address" =&gt; array(
                  "first_name" =&gt; "Jane",
                  "last_name" =&gt; "Smith",
                  "address1" =&gt; "123 Fake Street",
                  "phone" =&gt; "777-777-7777",
                  "city" =&gt; "Fakecity",
                  "province" =&gt; "Ontario",
                  "country" =&gt; "Canada",
                  "zip" =&gt; "K2P 1L4"
              ),
              "email" =&gt; "jane@example.com",
              ));
  
  $json_data = json_encode($data_array);
  var_dump($json_data);
  
  $options = array(
      'https' =&gt; array(
          'header'=&gt;  "Content-Type: application/json\r\n" .
              "Accept: application/json\r\n" .
              "Content-Length: " . strlen($json_data) . "rn",
          'method'  =&gt; 'POST',
          'content' =&gt; $json_data
      )
  );
  
  $context  = stream_context_create($options);
  $result = file_get_contents($order_url, false, $context);
  
  if ($result) {
      echo $result;
  }   else {
      echo "post failed";
  }
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>