Update Adalo database via API

Hello,
There is a way to create/delete/update adalo database itsems usign an API custom action?

Eg:
When the user login, I update all the field (in adalo database) of that user making an API call.

This would be nice to have, so in that way I would be better integrate external tools and keep using adalo database (that is better for relationship stuff)

Thank you so much

2 Likes

Not yet, but we currently have this in development: Adalo API to access collections data | Voters | Adalo

. Create an API Custom Action:

  • In your Adalo app, go to Settings > Custom Actions .
  • Click Create New Custom Action .
  • Give your action a descriptive name (e.g., “Update User Data”).
  • Set the Method to POST (or PUT for updating existing items).
  • Enter the URL of your API endpoint where you’ll be sending the request.
  • For Headers , add any necessary headers (e.g., authorization, content-type).
  • For Body , define the structure of the data you’ll be sending to the API. You’ll likely need to include the user’s ID and the updated field values.

2. Set Up Your API Endpoint:

  • Create an API endpoint (using a backend language like Node.js, Python, or Ruby) that will handle the incoming requests.
  • The endpoint should:
    • Authenticate the request to ensure it’s coming from your Adalo app.
    • Extract the user’s ID and updated field values from the request body.
    • Update the corresponding user’s data in your Adalo database.
    • Return a success message or error code indicating the result of the operation.

3. Trigger the Custom Action:

  • In your Adalo app, create a Button or On Login action.
  • Add the API Custom Action you created as a child action.
  • Pass the user’s ID and any other necessary data to the custom action.

Example API Endpoint (Node.js):

JavaScript

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const axios = require('axios'); // For making requests to Adalo's API

app.use(bodyParser.json());

app.post('/update-user', async (req, res) => {
  // Authenticate the request (e.g., using a secret key)

  const userId = req.body.userId;
  const updatedFields = req.body.updatedFields;

  try {
    // Make a request to Adalo's API to update the user's data
    const response = await axios.put('https://api.adalo.com/v1/collections/your-collection-id/items/' + userId, updatedFields, {
      headers: {
        'Authorization': 'Bearer your-adalo-api-token'
      }
    });

    res.json({ message: 'User data updated successfully' });
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: 'Failed to update user data' });
  }
});

app.listen(3000, () => {
  console.log('Server listening on port 3000');
});