1

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?

1 Answers1

1

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?

Mark McDonald
  • 7,571
  • 6
  • 46
  • 53
  • It is the first block of code, the JSON above the ajax example @Mark – Brenton Pierce Feb 17 '14 at 14:33
  • No problem, I'll check that. I was logging the id, and it appeared to be valid from the "response.id" in the previous call to create the table. I'll check there and make sure i'm getting the right "id" – Brenton Pierce Feb 18 '14 at 00:55
  • Still can't get this to work. I've verified that the table being created is the table id. I'm stumped. – Brenton Pierce Feb 19 '14 at 22:46
  • 1
    Ok, i've been able to get them to submit when i send them to a table already created. But here's the kicker, i am dynamically creating a table. then waiting 2 seconds before trying to add features to that table. @mark – Brenton Pierce Feb 20 '14 at 01:51
  • Ahhhh you've run into a known issue. It is noted in [a tiny corner of the docs](https://developers.google.com/maps-engine/documentation/table-create#known_issues). Your idea of waiting for a couple of seconds is currently what Google recommend. – Mark McDonald Feb 21 '14 at 03:52
  • thanks @mark send me a pm, i'd like to know more of what you use google map engine for. – Brenton Pierce Feb 21 '14 at 16:39