API "Action' is missing" with return code 200

Hello,

I call the API from a Google App Script project with this kind of body:

 

 

function add_booking(body) {
  const app_id = 'XXX';
  const access_key = 'V2-XXX';
  const table_name = 'mytable';
  const url = 'https://api.appsheet.com/api/v2/apps/' + app_id + '/tables/' + table_name + '/Action';

  const headers = {
    'applicationAccessKey':access_key
  };

  const payload = {
    'Action':'Add',
    'Properties':{},
    'Rows':[
      {
        'name':'some data'
      }
    ]
  };

  const options = {
    'method': 'post',
    'content-type': 'application/json',
    'headers': headers,
    'payload': JSON.stringify(payload)
  };

  const response = UrlFetchApp.fetch(url,options);
  const status = response.getResponseCode();

  Logger.log("RESPONSE_STATUS=" + status);
}

 

 

 I have a return code of 200 which is "success" according to the AppSheet documentation.

 

 

22:25:26	Infos	RESPONSE_STATUS=200

 

 

However, no records are added to the targetted table.

The Audit Log tool shows two lines:

Capture d’écran 2022-03-24 223737.png

 

First line shows success with an error (??):

 

Properties:
 {
  "RestAPIVersion": 2,
  "TableName": "mytable",
  "AppTemplateVersion": "1.000091",
  "Errors": "'Action' is missing.",
  "AppTemplateName": "XXX",
  "Operation": "REST API invoke",
  "RecordType": "Stop",
  "Result": "Success",
  "ResultSuccess": true,
  "StatusCode": "OK"
}

 

The seconde one shows the actual error:

 

 

REST API:
{
  "Action": "'Action' is missing.",
  "Properties": {},
  "Rows": []
}

Properties:
 {
  "RestAPIVersion": 2,
  "TableName": "mytable",
  "AppTemplateVersion": "1.000091",
  "Errors": "'Action' is missing.",
  "AppTemplateName": "XXX",
  "Operation": "REST API invoke",
  "RecordType": "Start",
  "Result": "Failure"
}

 

 

 

 

I have no clue of what happening here. The only thing i found is this item where a bug was found and fixed right away.

What can i do now?

Solved Solved
0 10 389
1 ACCEPTED SOLUTION

"contentType", not "content-type"

😜

That darn crazy code, always making mountains out of mole hills...

---------

Reading through the thread, I initially had the same thoughts as John, properties not being blank, double quotes instead of single. Guess not. But just to provide some validation to you John, I'm extremely certain that at one point, leaving out the Properties did cause an error, but maybe they improved that since then.

Before figuring it out for you, I was going to suggest completely deleting your entire code, and re-writing it from scratch. That probably would have worked in this case, so keep that in mind for the future. It's a lot harder to make the same tiny mistakes when you can't even see the old mistake anymore.

What I actually ended up doing was copying OP's code to my own appsheet API GAS, filling in my own details and running it against my own app to test. Got the exact same error, so I slowly went through line-by-line comparing to my own working code, and eventually saw the difference noted above.

Good luck!

View solution in original post

10 REPLIES 10

I believe that AppSheet requires some Properties.   Creating an API call from within an app results in a template created that has the Properties shown below.  I tried removing them thinking they were not needed and received errors, so I just go with them.  I also wonder about the double versus single quotes.  I am not experienced enough to know which style of quoting is required - or if it matters.

As for the success vs failure, notice the RecordType.  I believe what the results are trying to convey is that while the call failed,  the service was able identify, react to the error and exit gracefully.    This is different from an unexpected error where all processing is halted and the encountered error code/message is simply sent back to the caller.

Example API Properties List

{
"Action": "Add",
"Properties": {
"Locale": "en-US",
"Location": "<<42.80890903597787, -71.6389241275992>>",
"Timezone": "Eastern Standard Time",
},
"Rows": [
...
}

 

Thank you for your answer, unfortunately it does not fix my problem.

I tried to create a simple app with a simple table (id, value) to call the API from a simple script :

function test_api() {
  const url = "https://api.appsheet.com/api/v2/apps/XXX/tables/mytable/Action"
  const options = {
    "method":"post",
    "content-type":"application/json",
    "headers":{
      "applicationAccessKey":"V2-XXX"
    },
    "payload":JSON.stringify({
      "Action":"Add",
      "Properties":{
        "Locale":"fr-FR",
        "Location": "45.574522, 5.925060",
        "Timezone": "Central European Time"
      },
      "Rows":[
        {
          "value":"HelloWorld!"
        }
      ]
    })
  }

  const response = UrlFetchApp.fetch(url, options)
  const status = response.getResponseCode()
  const data = response.getContentText()

  Logger.log("RESPONSE_STATUS=" + status)
  Logger.log("RESPONSE_DATA=" + data)
}

I still have the same issue. I tried to use the same properties as you as well, no difference.

Notes:

  • Properties are optionnals according to the documentation.
  • Using simple or double quote make no difference on this issue.

Ok, I've just spent a lot of time with API calls and now carefully looking over your script. 

The JSON is fine...however, I don't think the "applicationAccessKey" is correct.  It should be something like "V2-jZhAd-eVRka-k6suy-QVRlA-imt4g-msyg6-n1NSH-y3TkP".

In case you don't know, this key is required to determine:

1) That web calls are enabled to the app.

2)  That the requested Action is allowed by the app.

To get the key for your app (just in case you don't know but for others who are reading this as well), see the image below for its location.   Tap the "Create Application Access Key" button and then tap "Show Access Key" to copy it.

 

Screen Shot 2022-03-28 at 1.37.38 PM.png

Hello, thanks for the time you give me 

I don't think the problem comes from there because I masked the AppId and the API Key before sharing the code.

I'm out of solutions...

I have not used a script to call an API before so I don't know all of the mechanics of it.  But going back and focusing on the error message it states 'Action' is missing with the word Action in quotes meaning the word Action literally.

Reviewing your original posted script code, I see that you have "Action" at the end of the URL and the only place I can see where "Action" is used that's not a parameter name.  Maybe it's not needed there?  Because it's in the payload?

I thought the same thing so i tries to remove it : i got an error as a response. I also tried to change it and put "Add" instead, got the same 'Action' is missing

How do you call the API ? I could try another way and confirm that the issue comes from my code.

I am using automation from within the App itself and using the API to perform bulk adds.

I am pulling in @Marc_Dillon .  He has had experience with the API.  Maybe he has some insight to give.

"contentType", not "content-type"

😜

That darn crazy code, always making mountains out of mole hills...

---------

Reading through the thread, I initially had the same thoughts as John, properties not being blank, double quotes instead of single. Guess not. But just to provide some validation to you John, I'm extremely certain that at one point, leaving out the Properties did cause an error, but maybe they improved that since then.

Before figuring it out for you, I was going to suggest completely deleting your entire code, and re-writing it from scratch. That probably would have worked in this case, so keep that in mind for the future. It's a lot harder to make the same tiny mistakes when you can't even see the old mistake anymore.

What I actually ended up doing was copying OP's code to my own appsheet API GAS, filling in my own details and running it against my own app to test. Got the exact same error, so I slowly went through line-by-line comparing to my own working code, and eventually saw the difference noted above.

Good luck!

Okay, thanks a lot! That part wasn't from me, i'm new with API. I think a may have make the same mistake. But it works now!

Actually, i also tried with no Properties, it still works.

Awesome!  Great post.  I've learned something new myself.

Top Labels in this Space