oauth 2.0 - Use Apps Script URLFetchApp to access Google Datastore Data -


i want experiment google datastore via apps script because have current solution based on google sheets runs timeout issues inherent in transacting drive files. i've created test project in google cloud service account , enabled library mzx5dznpsyjvyzar67xxjqai_d-phda33 (cgoa) handle oauth2 work. followed guide start here , got pertinent confirmation works token (and removing token throws 'authentication failed prompt').

now want start basic query display 1 entity put in. can use api explorer here , run query body:

{    "query": {} } 

and result:

{  "batch": { "entityresulttype": "full", "entityresults": [   {     "entity": {       "key": {         "partitionid": {           "projectid": "project-id-5200707333336492774"         },         "path": [           {             "kind": "transaction",             "id": "5629499534213120"           }         ]       },       "properties": {         "commentin": {           "stringvalue": "my first test transaction"         },         "status": {           "stringvalue": "closed"         },         "auditstatus": {           "stringvalue": "logged"         },         "user": {           "stringvalue": "john doe"         },         "start": {           "timestampvalue": "2017-08-17t18:07:04.681z"         },         "commentout": {           "stringvalue": "done today!"         },         "end": {           "timestampvalue": "2017-08-17t20:07:38.058z"         },         "period": {           "stringvalue": "08/16/2017-08/31/2017"         }       }     },     "cursor": "ckispgogc35whh9qzwn0lwlkltuymda3mdcwoda1mdy0oti3nzrygassc1ryyw5zywn0aw9ugicagicagiakdbgaiaa=",     "version": "1503004124243000"   } ], "endcursor": "ckispgogc35wcm9qzwn0lwlkltuymdaxxdcwoda1mdy0oti3nzrygassc1ryyw5zywn0aw9ugicagicagiakdbgaiaa=", "moreresults": "no_more_results"  } } 

i try same thing code:

 function doget(e)   {    var goa = cgoa.goaapp.creategoa('oauth2-service-account',    propertiesservice.getscriptproperties()).execute(e);     if(goa.hastoken()) {var token = goa.gettoken();}        var payload = {"query":{}}             ;           var result = urlfetchapp.fetch('https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runquery',                       {                       method: "post",                         headers: {authorization: "bearer " + goa.gettoken()},           mutehttpexceptions : true,                        payload: payload                      });            logger.log(result.getblob().getdataasstring());           } 

and error in logger:

   "error": {      "code": 400,      "message": "invalid json payload received. unknown name \"query\": cannot bind query parameter. 'query' message type. parameters can bound primitive types.",      "status": "invalid_argument",      "details": [        {          "@type": "type.googleapis.com/google.rpc.badrequest",          "fieldviolations": [            {              "description": "invalid json payload received. unknown name \"query\": cannot bind query parameter. 'query' message type. parameters can bound primitive types."            }          ]        }      ]    }  } 

if try use word such 'resource' or 'gqlquery', error:

  "error": {      "code": 400,      "message": "invalid json payload received. unknown name \"gqlquery\": cannot bind query parameter. field 'gqlquery' not found in request message.",      "status": "invalid_argument",      "details": [        {          "@type": "type.googleapis.com/google.rpc.badrequest",          "fieldviolations": [            {              "description": "invalid json payload received. unknown name \"gqlquery\": cannot bind query parameter. field 'gqlquery' not found in request message."            }          ]        }      ]    }  } 

i can't tell api documentation syntax supposed be. can tell me how compile functional request body apps script datastore?

you need set contenttype of payload stringify json payload follows:

var result = urlfetchapp.fetch(     'https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runquery',     {         'method':'post',         'contenttype':'application/json',         'headers': {authorization: "bearer " + goa.gettoken()},         'payload':json.stringify(payload)     } ); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -