Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

Create an API that listens to any event happening on a specific Monday.com board.

  1. User

    Create an API that listens to any event happening on a specific Monday.com board.

  2. Assistant

    To create an API that listens to events happening on a specific Monday.com board, you can use Monday.com's API and webhook functionality. Here are the steps to implement it:

    1. Obtain a Monday.com API key: Visit the Monday.com developers page (https://monday.com/developers/v2/overview/authentication/) and generate an API Key. You will need this key to authenticate API requests.

    2. Create a webhook: Webhooks allow you to receive real-time updates about specific events on your board. Use the Monday.com API to create a webhook for your desired board. You need to provide the board ID and a callback URL where the webhook payload will be sent.

      Endpoint: POST /v2/webhooks Example Request Payload:

      {
        "boardId": <YOUR_BOARD_ID>,
        "url": <CALLBACK_URL>,
        "event": "all"
      }
      
    3. Set up a server to handle incoming events: Create a server or script that listens to the callback URL defined in the webhook. This server should be accessible from the internet so that Monday.com can send payloads to it.

    4. Handle incoming events: Whenever an event occurs on your Monday.com board, Monday.com will send a payload to your callback URL. Parse the payload and handle the events accordingly in your server script. The payload will contain information about the board, the item that was changed, the changed column values, and more.

    5. Implement the desired logic: Based on the events received from Monday.com, perform the required actions or execute the desired logic in your API. You can update a database, send notifications, trigger other workflows, or perform any other custom actions as needed.

    By following the above steps, you can create an API that listens to events happening on a specific Monday.com board and handle them in real-time.

  3. User

    Create a sample node js express app, to listen to the above web hook and add all the event logs to a mongo table

  4. Assistant

    Sure! Here's an example of how you can create a Node.js Express app to listen to the webhook events from a Monday.com board and store them in a MongoDB table:

    First, make sure you have the necessary dependencies installed. Run the following command in your project directory to install the required packages:

    npm install express mongoose body-parser
    

    Next, create a file called server.js and add the following code:

    const express = require('express');
    const mongoose = require('mongoose');
    const bodyParser = require('body-parser');
    
    const app = express();
    
    // Body Parser Middleware
    app.use(bodyParser.json());
    
    // MongoDB Connection
    mongoose.connect('mongodb://localhost:27017/monday_events', {
      useNewUrlParser: true,
      useUnifiedTopology: true
    });
    mongoose.Promise = global.Promise;
    
    const eventSchema = new mongoose.Schema({
      boardId: String,
      event: String,
      payload: Object,
    });
    
    const Event = mongoose.model('Event', eventSchema);
    
    // Webhook route to handle events
    app.post('/webhook', async (req, res) => {
      try {
        const { boardId, event } = req.body;
        const payload = req.body;
    
        // Save event to MongoDB
        const newEvent = new Event({
          boardId,
          event,
          payload,
        });
        await newEvent.save();
    
        res.sendStatus(200);
      } catch (err) {
        console.error(err);
        res.sendStatus(500);
      }
    });
    
    // Start the server
    const port = 3000;
    app.listen(port, () => {
      console.log(`Server started on port ${port}`);
    });
    

    In the above code, we create an Express server that listens for POST requests on the /webhook route. When an event is received, it saves the event data (boardId, event type, and payload) to a MongoDB collection called "events".

    Make sure to replace the MongoDB connection URL (mongodb://localhost:27017/monday_events) with your own MongoDB connection string.

    To run the server, use the following command:

    node server.js
    

    Now, the Express app is set up to listen for events from the Monday.com webhook and store them in the MongoDB table. You can modify the schema, collection name, or database name as per your requirements.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.