Call an Action with an API

Just starting out on using the Api so be gentle

I’ve managed to get an API to write data into a subtable using both fixed text and variables encoded in the body e.g.

{
"Action": "Add",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC",
},
"Rows": [
{
"Business": "<<[_ThisRow].[BusinessID]>>",
"ContactID": "<<UniqueID()>>",
"ContactCreation": "<<Today()>>",
"ContactMod": "",
"ContactUser": "<<UserEmail()>>",
"Type": "Test",
"Details": "foo",
},
{
"Business": "<<[_ThisRow].[BusinessID]>>",
"ContactID": "<<UniqueID()>>",
"ContactCreation": "<<Today()>>",
"ContactMod": "",
"ContactUser": "<<UserEmail()>>",
"Type": "Test",
"Details": "bar",
}
]
}

what I’m trying to do now is basically the same but for the API to call an action to create the records. I’ve already created a “Add a new row to another table using values from this row”. The action works fine. What I’m struggling with is how to code the body. Since the action already calculates all the values for the row to be created. I’ve tried:

{
"Action": "TestAction2",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC",
}
{
"Action": "TestAction2",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC",
},
"Rows": []
}
}

I dont get any errors. I can see the action button triggers the workflow and the workflow reads the right data. But the result in the monitor is

#
3
Name
New process 2-returnStep
Created TimeStamp
23/11/2021, 10:40:30 am
Output data
{}


I need it to work this way (an API calling an existing action) as I have a very complicated action that can create 200+ rows. But its taking 10-20mins!!! to create all those rows. Which isn’t ideal for someone using the app to see 200+ in the sync queue. So my thought was to simply create a trigger that runs a Bot that calls the API that calls the action.

0 23 630
23 REPLIES 23

My understanding is this is not going to work with API, as it is backend service. API does not know which of [_thisrow] is going to be, as it is not triggerd by row data change event.
To do the same, pick up “add” event as API varb instead of triggering actions.

For the moment, your API call may work, but ID values returns null, so nothing is going to happen.

[_ThisRow].[BusinessID] and just [BusinessID] worked fine when I used an action button in the parent record to trigger the bot.

Im begining to wonder if the issue relates to the fact I have an action triggering a bot which calls the API which calls another action. Am I correct in thinking that if you have a process that goes Action → Bot → Action the 2nd action will not run so as to stop any infinite loops? Which actually matches what I’m seeing.

@Steve @tsuji_koichi do you know? If so do I have to use Google Apps Script to make it work like this?

I assumed your BOT is schedule driven.

But I still suppose thisrow syntax may not work with api but I’m not perfectly sure.

I’m afraid I have no experience with the API, and am still avoiding Automation, so I don’t have a whole lot of experience with it, either.

By the way I’m not sure why you use api on this occasion rather than fire action by the bot. They are equivalent I believe .

If you want to fire action externally out of Appsheet app , using api is making sense. But you are using thisrow syntax which indicate you fire action from the same app. Better to fire action by simply bot.

Yes this is exactly what I want. But how can invoke the API if Action->Bot->API->Action isn’t allowed, assming thats the issue?

You have to provide a key value for the record that you want the Action to run on, in the “Rows”.

I see from your screenshot that [ContactID] is the key column for that Table. So you need to select a key value of some record in that Table, let’s call it “x”, for the Action to run on. Then in your API body, put this:

"Rows": [
  {
    "ContactID": "x"
  }
]

You’re not assigning values to columns here, you’re selecting which records to run the Action on.

Tried

{
"Action": "TestAction2",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC"
},
"Rows": [
{
"ContactID": "UniqueID001"
}
]
}

and

{
"Action": "TestAction3",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC"
},
"Rows": [
{
"ContactID": "UniqueID001"
}
]
}

neither works

Just to confirm. Is there an existing record in the Table with a key value of “UniqueID001” ?

So I want the user to be able to manually trigger this to happen. I did get it working fine in the background on a schedule just using bots. But even if I created mutliple schedules, one per hour, this wouldn’t be often enough.

Whats really annoying is doing this offline and then manually running the scheduled bot it takes about 10secs to complete. Whereas doing it all through a series of grouped actions takes 10-20mins to complete.

So in simple terms the user triggers it in table A, then the action looks at a subset of data in table B and copies this to table C.

Simon,

If you invoke a Data Change Action through the API, the resulting data changes will trigger workflow rules and bots exactly as if you had invoked the Data Change Action through the client. The triggered workflow rules or bots can do all of the normal workflow things like sending email, sending SMS, creating PDF files, and invoking a second set of Data Change Actions.

Any data changes you make through the second set of Data Change Actions will trigger workflow rules or bots in the normal way. In other words, it is fully recursive.

We keep a recursion count and limit the levels of recursion to 5. I am quoting the limit from memory, and it may be off, but there is a limit to prevent infinite recursion.

@Marc_Dillon So the issue here is that I already have grouped action that works fine, but it takes 10-20mins to run. Based on what I’ve read I should be able to simply call that Action with the API. I was hoping I’d be able to do that way and not have to reinvent-the-wheel by redoing it all through the body of an API.

I’ve tried about 20 different things today. The only conclusion I can come to is that if I start the API body with

{
"Action": "Add",

add then specify the columns in the API it works fine. But if I try to have the API call

{
"Action": "TestAction2",

then the API triggers but the return step in monitoring is ALWAYS

# 3
Name New process 2-returnStep
Created TimeStamp 24/11/2021, 02:05:49 pm
Output data {}

i.e. no data So I’m completely confused

I take it you think the Action did not run?

What is the full API call body that you used?

{
"Action": "TestAction3",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC",
},
"Rows": [
{
"ContactID": "<<UniqueID()>>",
"Type": "TestAction3 from API",
"Details": "456",
},
]
}

Also tried

{
"Action": "TestAction3",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC",
},
"Rows": []
}

and

{
"Action": "TestAction3",
"Properties": {
   "Locale": "en-GB",
   "Timezone": "UTC",
},
}


origionally also tried with testaction2

Column details

No the action does not appear to run. When i get it to display either of the above and manually click on then it creates rows fine. But not if the API calls them

No I’m trying to create a new record

You’re still not understanding then. An invoked Action needs to be run from the context of an existing record

@Marc_Dillon I think I’m piecing it altogether now… The documentation isn’t clear

1 = I was looking for errors in Bot Monitor, not the Log Analyser
2 = You can ONLY create rows from within the API Body using “Add”. Not with an action
3 = The one action type you are allowed to call in the API body can only update rows

Log Analyser is typically the best place to go to really see what’s going on.

I’m not sure what you mean here. “within the API Body”?

To create new records via API, you can either:

  1. Use the basic “Add” API Action.
  2. Invoke an “add new row to another table with values from this table” Action, as I just proved in the other thread:
    Edit key column - #5 by Marc_Dillon

Yes, that’s basically what the docs says. But again, as I just tested in the other thread, that’s not necessarily true.

So I think whats going wrong here is I’m not calling the API from the correct table/s.

This is the action I want to call:

This is the API settings currently
3X_2_f_2f91142106f2f99586d8225b22339b64e3dfe283.png

I’ve not idea at all now whats happening because even the log analyser is telling me the Bot ran succesfully

What do you suggest I need to change?

Top Labels in this Space