1

So here is my code, i've already made the oauth handshake, and that has given me the authentication token which i'm including in my header. I am simply trying to batch insert some features into an existing table. I keep getting a 400 "parseError" - This API does not support parsing form-encoded input.

Here's some of my code. I have no idea where i'm derping any ideas.

$(document).ready(function(){
$('.pickTrip').bind('click', function(){
      var pointData = {
                      "features": [
                        {
                          "type": "Feature",
                          "geometry": {
                            "type": "Point",
                            "coordinates": [
                              -87.397980,
                              44.795067
                            ]
                          },
                          "properties": {
                            "gx_id": "1242342",
                            "name": "Jimmy Choo",
                            "phone": "(920)555-4242",
                            "email": "jchoo@aol.com",
                            "vehicle": "mazda, b2300, 1994"
                          }
                        }
                      ]
                    };
                    console.log(pointData);
      var url = "https://www.googleapis.com/mapsengine/v1/tables/{table id}/features/batchInsert";

      jQuery.ajax({
        type: "POST",
        url: url,
        data: pointData,
        dataType: '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);
        }
      });

});
});

1 Answers1

1

jQuery takes the object provided in the 'data' parameter and turns the key/value pairs into an encoded query string. You will want to send the raw JS object and make sure it's not marked as form encoded. To do that, change the 'dataType' parameter to 'contentType' and update the data value to take the "stringified" version of the JSON object.

Like this:

    data: JSON.stringify(pointData),
    contentType: 'application/json',
Mark McDonald
  • 7,571
  • 6
  • 46
  • 53