title: OAuth, OAuthConfig, & Google Apps Script (Fusion Table API - SQL Insert Problems)
body: <p>I am developing a google apps script function that will insert a row into a fusion table. Most of my fusion table interface works fine but this is my first attempt at an sql 'POST' query. Based on the documentation <a href="https://developers.google.com/fusiontables/docs/v1/using#insertRow" rel="nofollow noreferrer">here</a> I should be able to put the sql statement within the POST body. I've reduced myself to the <a href="https://developers.google.com/oauthplayground/" rel="nofollow noreferrer">OAuth Playground</a> for troubleshooting  and I keep getting the following error. I've been trying to use the sql insert statement <code>sql=INSERT INTO {fusionId} (HeadingName) VALUES (ValueOne)</code> and I have tried various variations of this statement to no avail. Please help me determine the proper syntax or method to do this.</p>
  
  <pre><code>{
   "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "required",
      "message": "Required parameter: sql",
      "locationType": "parameter",
      "location": "sql"
     }
    ],
    "code": 400,
    "message": "Required parameter: sql"
   }
  }
  </code></pre>
  
  <p>Once I figure this out, I then need to duplicate the playground operation within my code, which (I think) will look something like this:</p>
  
  <pre><code>function fusionRequest(methodType, sql, oAuthFields) {
    OAL.googleAuth(oAuthFields);
    var options =
      {
        oAuthUseToken : "always",
        oAuthServiceName : 'fusiontables',
        method : "POST",
        payload : "sql=INSERT INTO {fusionId} (Heading) VALUES (ONE)",
        contentType : "application/json"
      };
  Logger.log(options)
    var fetchResult = UrlFetchApp.fetch(oAuthFields.queryUrl, options);
    return JSON.parse(fetchResult.getContentText());  
  }
  </code></pre>
  
  <p>I've been thinking it could also be a problem with the content-type, but I am at a loss. Please help.</p>
  
  <p><strong>Update #1</strong>
  By using Sanya's advice I was able to get the request working in the OAuth Playground. However, I'm still struggling with the request in the code. I am getting repeated requests for authorization when running the code (or a general OAuth Error when debugged). From my previous experience <a href="https://stackoverflow.com/questions/14970059/getting-google-apps-script-to-authorize-fusion-table-api/15460718">here</a>, I believe this means that there is still something wrong with my payload. Any advice on this would be much appreciated.</p>
  
  <pre><code>var oAuthFields = {
    'clientId' : '523606257547.apps.googleusercontent.com',
    'scope' : 'https://www.googleapis.com/auth/fusiontables',
    'fetchUrl' : 'https://www.googleapis.com/fusiontables/v1/',
    'clientSecret' : 'L-f8DgwK4rs7Qmw9k5IFL7lZ',
    'fusionId' : '1b4kT_aYRfNBy8ZPtSZqhQUqVSVIYj_QWiBmjXXI',
    'service' : 'fusiontables',
    'queryUrl' : 'https://www.googleapis.com/fusiontables/v1/query/'
  };
  function fusionRequest(methodType, sql, oAuthFields) {
    OAL.googleAuth(oAuthFields);
    var options =
      {
        oAuthUseToken : "always",
        oAuthServiceName : 'fusiontables',
        method : "POST",
        payload : "sql=INSERT INTO {fusion id} (\'Heading\') VALUES (\'ONE\')",
        contentType : "application/x-www-form-urlencoded"
      };
    var fetchResult = UrlFetchApp.fetch(oAuthFields.queryUrl, options);
    return JSON.parse(fetchResult.getContentText());  
  }
  </code></pre>
  
  <p>For context, the googleAuth() function and overall layout of this function is the same as a function I use to add columns in the fusion table (which works).</p>