title: Sending a JSON Request to API using cURL
body: <p>I have seen examples of people sending JSON data in an array. An using cURL to send the data. Problem is most of them are something like</p>
  
  <pre><code>    $data = array('first_name' =&gt; 'Thomas', 'last_name' =&gt; 'Woods')
  </code></pre>
  
  <p>My question is, if I have something like below that isnt as dry cut. Example:</p>
  
  <pre><code>    "products": [
  {
    "product_id": "B00I9KDFK0",
    "quantity": 1,
    "seller_selection_criteria": [
      {
        "condition_in": ["New"],
        "international": false,
        "handling_days_max": 5
      }
    ]
  }
  </code></pre>
  
  <p>],</p>
  
  <p>So how would I put that info into an Array?</p>
  
  <p>More Info: Ive tried the following with no luck</p>
  
  <pre><code>    &lt;?php
      // Your ID and token
  
  
      // The data to send to the API
      $postData = array(
          'client_token' =&gt; 'XXXXXXXXXXXXXXXXXXXXXX',
          'retailer' =&gt; 'amazon',
          'products' =&gt; array('product_id' =&gt; '0923568964', 'quantity' =&gt; '1',                       'seller_selection_criteria' =&gt; array('condition_in' =&gt; 'New', 'international' =&gt;         'false', 'handling_days_max' =&gt; '5')),
          'max_price' =&gt; '1300',
          'shipping_address' =&gt; array('first_name' =&gt; 'Thomas', 'last_name' =&gt;             'XXXXX', 'address_line1' =&gt; 'XXXXXX Loop', 'address_line2' =&gt; '', 'zip_code' =&gt;         'XXXXX', 'city' =&gt; 'XXXX', 'state' =&gt; 'MS', 'country' =&gt; 'US', 'phone_number' =&gt;         'XXXXXX'),
  'is_gift' =&gt; 'false',
  'gift_message' =&gt; "",
  'shipping_method' =&gt; 'cheapest',
  'payment_method' =&gt; array('name_on_card' =&gt; 'XXXXXXXX', 'number' =&gt; 'XXXXXXXXXXXX', 'security_code' =&gt; 'XXX', 'expiration_month' =&gt; 'XX', 'expiration_year' =&gt; 'XXXX', 'use_gift' =&gt; 'false'),
  'billing_address' =&gt; array('first_name' =&gt; 'Thomas', 'last_name' =&gt; 'XXXXXX', 'address_line1' =&gt; 'XXXXXXXXX', 'address_line2' =&gt; '', 'zip_code' =&gt; 'XXXXXX', 'city' =&gt; 'XXXXXXXX', 'state' =&gt; 'MS', 'country' =&gt; 'US', 'phone_number' =&gt; 'XXXXXXXX'),
  'retailer_credentials' =&gt; array('email' =&gt; 'XXXXXXXX', 'password' =&gt;         'XXXXXXXXX')
      );
  
      // Setup cURL
      $ch = curl_init('https://api.zinc.io/v0/order');
      curl_setopt_array($ch, array(
  CURLOPT_POST =&gt; TRUE,
  CURLOPT_RETURNTRANSFER =&gt; TRUE,
  CURLOPT_POSTFIELDS =&gt; json_encode($postData)
      ));
  
      // Send the request
      $response = curl_exec($ch);
  
      // Check for errors
              if($response === FALSE){
          die(curl_error($ch));
      }
  
      // Decode the response
      $responseData = json_decode($response, TRUE);
  
      // Print the date from the response
      echo $responseData['published'];
      echo $response;
      ?&gt;
  </code></pre>
  
  <p>There error im getting is:</p>
  
  <pre><code>    {"_type":"error","_request_id":"5663c16b75f682d920000758","code":"invalid_request","message":"Validation failed on the request.","data":{"validator_errors":[{"value":[],"path":"products","message":"'' is not a permitted value for 'products' field."}]},"host":"zincapi-5","offers_urls":[],"screenshot_urls":[],"_created_at":"2015-12-06T05:02:35.567Z"}
  </code></pre>
  
  <p>Here is the code from the Echo of Json_echo</p>
  
  <pre><code>    {"client_token":"xxxxxxxxxxxxxxxxxxxxxxx","retailer":"amazon","products":{"product_id":"0923568964","quantity":1,"seller_selection_criteria":{"condition_in":"New","international":false,"handling_days_max":5}},"max_price":"1300","shipping_address":{"first_name":"Thomas","last_name":"xxxxxx","address_line1":"xxxxx","address_line2":"","zip_code":"xxxx","city":"xxxxx","state":"MS","country":"US","phone_number":"xxxxxx"},"is_gift":"false","gift_message":"","shipping_method":"cheapest","payment_method":{"name_on_card":"xxxxxxxxxx","number":"xxxxxxxxxxxxx","security_code":"xxxx","expiration_month":"xx","expiration_year":"xxxx","use_gift":false},"billing_address":{"first_name":"Thomas","last_name":"xxxxx","address_line1":"xxxxxxx","address_line2":"","zip_code":"xxxx","city":"xxxxxx","state":"MS","country":"US","phone_number":"xxxxxx"},"retailer_credentials":{"email":"xxxxxxxxxx","password":"xxxxxxxxxx"}}
  </code></pre>