Question

Trying to bulk insert features into a table. Here is my json

{"features":[{"type":"Feature","geometry":{"type":"Point","coordinates":["-80.358681","27.643045"]},"properties":{"gx_id":"84","address":"9037 Somerset Bay Lane, Vero Beach Port St. Lucie FL 32963","name":"x","phone":"x","email":"x","vehicle":"Cadillac ATS"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-81.819611","26.380350"]},"properties":{"gx_id":"85","address":"3951 Lakemont Drive, Bonita Springs Fort Meyers FL 34134","name":"x","phone":"x","email":"x","vehicle":"Toyota  Highlander"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-82.677773","27.427950"]},"properties":{"gx_id":"86","address":"6809 Gulf Of Mexico Dr Longboat Key Sarasota FL 34228","name":"x","phone":"x","email":"x","vehicle":"Cadillac  SRX"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-82.677773","27.427950"]},"properties":{"gx_id":"87","address":"6809 Gulf Of Mexico Dr Longboat Key, Sarasota FL 34228","name":"x","phone":"x","email":"x","vehicle":"Cadillac SRX"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-81.818977","26.590782"]},"properties":{"gx_id":"88","address":"10381 McArthur Palm Lane, Fort Myers Fort Meyers FL 33950","name":"x","phone":"x","email":"x","vehicle":"Infinity M35"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-81.972443","28.908287"]},"properties":{"gx_id":"89","address":"The Villages, Lake Sumter Landing, Lady Lake Orlando FL 32162","name":"x","phone":"x","email":"x","vehicle":"VW Bettle"}}]}

Here is my Ajax

    function sendBatch(tableID, data){
        dataString = data;
        console.log(dataString);
        var url = "https://www.googleapis.com/mapsengine/v1/tables/"+tableID+"/features/batchInsert";

        jQuery.ajax({
            type: "POST",
            url: url,
            data: dataString,
            contentType: 'application/json',
            headers: {
              'Authorization': 'Bearer ' + authResult.access_token
            },
            success: function(response) {
              // Log the details of the Map.
              console.log(response);
            },
            error: function(response) {
              response = JSON.parse(response.responseText);
              console.log("Error: ", response);
            }
        });
    }

Here is the error i am getting

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "The value is invalid.",
    "locationType": "parameter",
    "location": "id"
   }
  ],
  "code": 400,
  "message": "The value is invalid."
 }
}

I am passing in features so i don't understand why it is having an issue. Anybody have any thoughts or ideas?

Was it helpful?

Solution

It's hard to tell without knowing what data / dataString you're sending to the API but the error says that "The value is invalid" at location "id". Chances are good that the value you are providing in the 'id' column is incorrect for the schema. That is, if you have set up a column called id, of type string and you're sending a double (for example) then you will get that error.

One thing to note is that the API requires that integers are sent as quoted strings in order to avoid loss of precision. Details are in the docs.


EDIT: I've managed to set up a table and insert your JSON with no problems. The error points to a location of "id", which I believe corresponds to the Table ID you provide in the URL. I had said it could be a feature property, but then the location would look like "features[0].properties.id". The error also specifies a "locationType" of "parameter". Can you check your tableID parameter and make sure it's valid?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top