API to update collection

Hello - I am trying to update a property from a Custom Action using the API for Adalo. I got the link to the API from the DB and tried to set it up. The custom action said the test was successful but when I implement the action nothing happens.

My goal is to update a column from False to True. The table (Collection) is Orders.

Image below is from the documentation:

And this is my custom action:

Not sure where I have gone off track. Any assistance would be appreciated.

Thank you
Ray

Hi @RayInBC,

Can’t test it right now, but I see two points to explore:

  • why do you add “Orders” to the JSON request? I assume that you’re updating an Order in Orders collection already, so I think you can leave only {“CompletionEmailSent”:true}
  • keep in mind that you’ve hardcoded record ID=1 into the API base URL (the very last figure in the field). If you’d like to update different record, then you need to set ID with magic text button (and also you need to get this ID somehow, but this is a different story).

Best,
Victor.

1 Like

Thanks Victor - The original code had the OrderOrderItems column included so I thought the code needed a reference to the main object. But I see the collection is referenced in the url. I have removed it from the code.

For this action there is only one record - the Order that is passed from the previous page. Should that work without having to deal with the recordID - I have been reading a bit about this and it seems to be a problem for some applications.

Unfortunately the code still doesn’t work.

Will keep digging. I appreciate your time.

Regards
Ray

Hi @RayInBC,

Here is the thing: this “…n5f/1” in the API request is an internal id of the record in the collection, which should be updated (of course the record, not the collection :slight_smile: ).

You need to know this ID somehow. The problem is, that there is no way to get the internal ID of the record from inside of the Adalo app. You can try to use some ways to guess it, but they can’t be 100% reliable.

So before updating, you need to run a “GET ALL” on the collection, filter the output, get the desired record ID, and only after that you can run PUT with data update. This is how it works as for now, according to my knowledge.

You can read the related discussion here: How to Access Record ID information

Hopefully this will improve one day :slight_smile:

Best regards, Victor.

Hi Victor – thank you. I think what you are telling me is that there is no simple solution :blush: – if I hear you correctly the elementID in the code listed for the documentation may not be the record I’m looking for and the only way I can match the correct number is by using a routine (as you suggested) to find it.

I appreciate your time on this. Will read the discussion you referenced and keep moving ahead.

Be safe

Ray

1 Like

Hi,
As Victor mentioned very well, the ID is set in the API base URL, where to get is not fully disclosed, but there are workarounds.

Made a couple of tests, and there a way to achieve this with one caveat, you cannot delete the orders from the collection (EDIT: You can if you use a control Collection with count(orders)).

How to perform this?

Every collection ID has the “id”, and as such and following DB rules, this is a primary key. if you delete that row, that key will never be attributed again, it passes to next. E.g. so if you delete record 3, then next created record will not be 3 again, but 4.

They way that can be done is, whenever you create an order, you have a field “Index” that does a “count orders” + 1. So when you create first record you get 0 + 1 = 1 ID, second record 1 + 1 = 2 ID. So this count follows the indexing of the table.

and you know then that Index is also the Internal ID of the record.

Record 1, you see ID is also 1 in the result and Index is 1
image

Record 2, same
image

I deleted record 3, so if you run the API, you get a 400 code.

Here I deleted record 3 to see what would come next.

Not an ideal world, but can help you use ADALO API until ADALO fixes this minor roadblock :). But cautious, can be a dangerous path if something breaks along the way :smiley: .

EDIT:
Actually maybe we can make this work even deleting an order. If you actually create and use a control collection, where you count the total orders, even if an order is deleted, the total count is there. you just need to update the control collection at same time of creation of the order (current count + 1 ).

So would be:
1,2,3,4 orders created, so next internal ID is 5

You delete order 3, but you still have a total count of 4. so the next Index will be total count (4) +1 = 5, which is actually the next primary key.

Thank you - I really do appreciate the assistance. I understand how complicated it can get if these numbers get out of sync. My background is DB and not Collections - so I get a bit concerned when there is even a chance that the records lose their connections. :slight_smile:

I am also quite weak in using JSON and APIs - I understand the concept but not much practical use, so I am learning as I go.

So after having said that - I went back to my app and manually changed the elementid to 5 - expecting it to exist somewhere in my orders table that has about 7 records in it. I set all the records for the CompletionEmailSent column to FALSE and ran my routine to finish an order and send the email (Custom Action). My hope was that the routine would change one of the records and I could at least verify the routine works. But unfortunately it did not. I don’t want to get too far ahead of myself with your work around until I can see that it works. Looking at my code in the previous posts is there a reason why it won’t work?

Is there a way to use the URLs in a browser to list the records with all the object items? I tried but it needs Authorization and I couldn’t find how to do that.

Cheers
Ray

Quick question - are you using coding software like visual studio to access the Adalo DB directly and check your code? If so are there documents with the setup available?

Tks

Hi @RayInBC,
I do all tests in POSTMAN. In the GET request you see clearly the ID “4”, the INDEX is the one calculated by the count.

Example

Brilliant - I was able to find the ID and it tested perfectly. I’m going to play with your code and see where we go. :slight_smile:

Will post when I’ve tried this out. But have other priorities for now.

Be safe
Ray

1 Like

Hello - I think I have a solution for the time being. I used Integromat to filter my list to get a recordID and then update that record. A bit of a workaround - but it’s working.

First I make a Webhook call to Integromat when I activate my Custom Action (button click)
Next I call for a list of records for that table (Orders)
Next I make a single record call from Adalo and filter the request using a unique number sent from the Custom Action (Order Number)
The result is a single record where I can capture the RecordID to make a PUT call back to Adalo and update the record

Whew :slight_smile:

I hope this is useful to anyone who has been working on this. But I still look forward to Adalo exposing the RecordID at some point in the future.

Thanks to everyone who has taken time to work on this.

Be safe
Ray

1 Like

Hi @RayInBC,
That is also a solution, but I thought you wanted to avoid other tools :slight_smile: . I suggested something similar here but with user ID, but works for records also:

Webhooks is great addition though, you can “mock” any additional to trigger the process. “Watch records” is more limited.

Hi all,

Just a couple of comments from my side

  • instead of Count you can use Maximum, then you could be sure that next “manual ID” will always be increased
  • it seems that internal IDs always increase and they are not recalculated (tested this), so probably your idea @JL_LJ reg. “manual ID” could work
  • if something goes out of sync - that’ll be a huge problem :slight_smile:
  • As for me, Integromat could be an option, but with 100s of records this will quickly become quite costly :wink:

Another interesting option to explore could be creating a new record using Custom action. The “internal id” is returned as a response (the first one in a JSON):

So, in theory, you can do something like:

  1. create new record with custom action
  2. get internal ID from the response and store it in some temporary variable (as usual, users collection accessed via Logged-in User)
  3. then somehow get an access to newly-created record (I can think of setting a unique random tag in some field while creating the new record on step 1 and then adding a custom list to the screen, filtered by this field-tag)
  4. automatically update the “ManualID” field by value from temp variable stored in step 2. Automatically means with countdown timer in this list.

This may work in theory. The biggest problem will be to create a relationships to other collections - you’ll have to handle it manually somehow (creating a record with custom action will not allow this).

Just my 2 cents

Best,
Victor.

Hi @Victor ,
Good approach also, but I feel, it is creating more workarounds around the solution, unless you believe it is more stable in this way (Unless we are saying the same in different words :smiley: )

As for MAX vs COUNT, are you referring to also record the MAX as a MAX(Internal ID) and the moment of creating new record? Because using COUNT or Max, as long as you record it in another collection and pull that data in the moment of creating new record, then all good, because you are pulling recorded data (Maybe was not clear in my initial explanation), unless ADALO would fail in recording that data.

Yes internal IDs don’t recalculate since they are primary keys, which makes a lot of sense.

Would be great to see the ids visible in Text fields or Input fields for better data management :slight_smile: .

Anyway, great inputs @Victor , nice to see another perspective.

1 Like

Update: after some experimenting, I came up with the following very simple idea: (1) “Watch for new records” in Integromat and then update the “Manual ID” field with the value from Adalo’s internal id.

I set “Watch records” to 5 mins, increased the max records received to 100.

And then update the record:

ID is my “Manual ID” in the collection. And Record ID is Adalo’s internal record ID.

And it seems to work:

Of course the update will take some time (as I understand “watch records” runs on schedule), but it seems to work:

Before - created 3 records by hand

After 5 minutes waiting:

So: @JL_LJ @RayInBC what do you think, what potential problems could we get here?

Best,
Victor.

P.S. @JL_LJ answering to your message - my approach is to make things as simple as possible, but sometimes there is no other way rather building “house of cards” to solve the problem :))
As for MAX, I’m referring to MAX of Manual IDs, when you create records in Adalo using Adalo’s builder interfaces. Here is the logic:

  • you create new records, with ManualID = collection → ManualID → Max+1
  • the numeration will be sequential
  • even if you delete one record, anyway the new record’s ManualID will be calculated based on the Max value of ManualIDs in the collection.

Best,
Victor.

1 Like

Hi @Victor ,
I think we are on to something solid :slight_smile: . I think in maybe adding the Integromat as the Control Index (Mostly due to the 5min limitation), and on the submission process of a new record, we could use the “Count” or “Max” + 1.

So I would like the following to get a “stable” platform and a monitoring process, specially for more heavy apps:

  1. When user is using the form for a new record(E.g. Order). There is a field (hidden) that is fed by an input text field with a “Count+1” or “Max+1”, this could be called “Index”, then user submits the record this is registered into the recored (Order in this example).

  2. After, there is Integromat running in those 5min interval and saving that data into a “Control Index”.

  3. In the end then there can be another task in Integromat with a condtional and router action checking if the control index = index, if FALSE, then we have a problem and it can send a notification, so we use with this preventive measures.

So using both processes, I think they can work out very well on both frontend and backend :slight_smile: and prevent in most times issues with lack of sync or data deletion.

Penny for your thoughts :slight_smile:

1 Like

Hi guys - thanks for the work on this. Excellent discussion.

My thoughts:

In my app I already create a unique number using the Max + 1 concept - that is my OrderNumber, which is how I filtered the request in Integromat to get a single record with the RecordID. In effect this is my index column. But as you noted we can call this what we like.

I use the Webhook because its instantaneous - I am going to try using it with a new record to confirm that it will work. (will notify shortly).

Really like step 3 - creating a check so we can watch what happens as the app works through different routines.

Cheers for now

1 Like

Okay - I was able to get this working when a new record is created using Webhook. A few more steps but it gives us immediate access to the RecordID and lets us store it in the Adalo DB for future use.

The email is just to let me know that it worked - will drop that once I start using it.

I’m going to try using the RecordID to update with a Custom Action in Adalo :slight_smile: - this is a good thing you’ve hit on Victor. And so simple - which is usually better.

Cheers

2 Likes

@RayInBC, don’t forget you are still limited by the Minimum Interval in Integromat despite webhook being “immediate”.

1 Like

Oops - got ahead of myself. Sorry - didn’t realize how Integromat works. So Victors original concept is much better. It does create some issues for me as my drivers can come across times when they need to add and order and work with it right away.

I still think this is a great way to capture the RecordID - :slight_smile:

1 Like