title: Fatal error: Uncaught Google_Service_Exception Google Sheets API PHP Error Adding Row
body: <p>Getting the following error:</p>
  
  <p><code>Fatal error: Uncaught Google_Service_Exception: { "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"0\" at 'data.values[1]': Cannot find field.</code></p>
  
  <p>Weirdly it only happens when the array I am adding has from the 7th index on. See full array below.</p>
  
  <pre><code>array (size=11)
        0 =&gt; int 2176
        1 =&gt; string '16 Bedroom Residence With Unique Design' (length=39)
        2 =&gt; string 'This residence has a proven solid rental income... (length=2224)
        3 =&gt; string '2095000' (length=7)
        4 =&gt; string '3000' (length=4)
        5 =&gt; string '16' (length=2)
        6 =&gt; string '16.5' (length=4)
        7 =&gt; string 'Tamarindo' (length=9)
        8 =&gt; string 'For Sale' (length=8)
        9 =&gt; string 'House' (length=5)
        10 =&gt; string 'Air Conditioning, BBQ Area, Close to Schools, Close to Shops, Fully Equipped, Fully Furnished, Internet / Wifi, Laundry Room, Parking, Private Garden, Private Pool, ' (length=165)
  </code></pre>
  
  <p>Here is the function I call to add the rows:</p>
  
  <pre><code>function insert_google_sheet($data)
  {
  
      require 'vendor/autoload.php';
  
      $client = new  \Google_Client();
      $client-&gt;setApplicationName('Properties Google Sheet');
      $client-&gt;setScopes([\Google_Service_Sheets::SPREADSHEETS]);
      $client-&gt;setAccessType('offline');
      $client-&gt;setAuthConfig(__DIR__ . '/credentials.json');
      $service = new Google_Service_Sheets($client);
      $spreadsheetID = '1_3o2B7kucFBNWLJ99CWKCJsePqfZgB2fi8U7AatFoow';
  
      $range = 'Properties';
  
      $body = new Google_Service_Sheets_ValueRange([
          'values'    =&gt; $data
      ]);
      $params = [
          'valueInputOption' =&gt; 'RAW'
      ];
      $insert = [
          'insertDataOption'  =&gt; 'INSERT_ROWS'
      ];
      $service-&gt;spreadsheets_values-&gt;append($spreadsheetID, $range, $body, $params, $insert);
  
  }
  </code></pre>
  
  <p>I repeat, it works well if I only have up to the sixth index in the array.</p>
  
  <p>________EDIT____________</p>
  
  <p>Gathering data to insert in Google Sheets form wordpress post</p>
  
  <pre><code>$insert_data = [];
      // Get Post Info
      $properties = get_posts(array(
          'numberposts'      =&gt; -1,
          'orderby'          =&gt; 'title',
          'order'            =&gt; 'ASC',
          'post_type'        =&gt; 'property',
      ));
  
      foreach ($properties as $property) {
          // Get Post Meta    
          $id = $property-&gt;ID;
          $title = $property-&gt;post_title;
          $description =  $property-&gt;post_content;
  
          $property_meta = get_post_meta($id);
          $price = $property_meta['_meta_price'][0];
          $area =   $property_meta['_meta_area'][0];
          $beds = $property_meta['_meta_bedroom'][0];
          $baths = $property_meta['_meta_bathroom'][0];
          // $featured = $property_meta['_meta_featured'][0];
  
          $property_location = get_the_terms($id, 'location');
          $property_location = $property_location[0]-&gt;name;
  
          $property_status = get_the_terms($id, 'status');
          $property_status = $property_status[0]-&gt;name;
  
          $property_type = get_the_terms($id, 'type');
          $property_type = $property_type[0]-&gt;name;
  
          $property_features = get_the_terms($id, 'features');
  
          if ($property_features) {
              $features = '';
              foreach ($property_features as $feat) {
                  $features .=  $feat-&gt;name . ', ';
              }
          }
  
          $data_array = array(
              $id,
              $title,
              $description,
              $price,
              $area,
              $beds,
              $baths,
              $property_location,
              $property_status,
              $property_type,
              $features
          );
          array_push($insert_data, $data_array);
      }
  
      insert_google_sheet($insert_data);
  </code></pre>