Creating a webhook through the api does not return the creation id but null

When doing a mutation create_webhook

mutation {
  create_webhook(board_id: 123123123123, 
      url: "https://some.domain.com/api/v1/webhooks/dapulse/receive", 
      event: change_column_value){
    id board_id
  }
}

I always get the response null.

{
  "data": {
    "create_webhook": null
  },
  "account_id": 123123123
}

Is this a bug?

2 Likes

+1
I experience the same problem.

solved the issue.

So it will return null if it cant create a webhook because the challenge that was posted to your url was not returned.

So when doing a the call

mutation {
  create_webhook(board_id: 123123123123, 
      url: "https://some.domain.com/api/v1/webhooks/dapulse/receive", 
      event: change_column_value){
    id board_id
  }
}

this endpoint will receive a POST request with

{
   "challenge":"RANDOM_CODE"
} 

if you dont return the same json, you will see null as seen above.
But if you do return the same json the request will succeed.

{
  "data": {
    "create_webhook": {
      "id": "123123123123",
      "board_id": 123123
    }
  },
  "account_id": 123123
}```

I think they fixed it in the last 2 days ± because I did returned the same json but still got null.
Now it works :slight_smile:

Hi @avivtzo, @mientjan

I am currently experiencing the same. Looks like my endpoint is not receiving the challenge POST. How did you construct your backend? Mine is Node JS with a few exposed endpoints:

router.post(“/autoid/subscribe”, authenticationMiddleware, autoIdController.subscribe);

router.post(“/autoid/unsubscribe”, authenticationMiddleware, autoIdController.unsubscribe);

router.post(“/autoid/webhookaction”, authenticationMiddleware, autoIdController.webhookAction);

The first two routers (subscribe and unsubscribe) are receiving request from the custom trigger and are working just fine. The 3rd one was meant to be an endpoint to receive request from a webhook I am trying to insert from my backend into a board.

Tips are always welcome :slight_smile:

Where are you creating the webhook? In the developer playground or via an endpoint in your backend?

I setup my Express server with the following and snippet and when creating webhook in the developer playground had now issues.

export const incomingItem = async (req, res) => {
  try {
    const { challenge } = req.body;
    if (challenge) return res.send({ challenge });
    // Custom Logic
    res.status(200).send();
  } catch (e) {
    console.log(e);
    res.status(400).send();
  }
};
1 Like

Hi @kamescg

Thank you very much. I am creating the webhook via an endpoint in my backend. Using custom triggers I have 4 endpoint for this feature (subscribe, unsubscribe, webhookaction and recipeaction).

router.post(“/autoid/subscribe”, authenticationMiddleware, autoIdController.subscribe);
router.post(“/autoid/unsubscribe”, authenticationMiddleware, autoIdController.unsubscribe);
router.post(“/autoid/webhookaction”, authenticationMiddleware, autoIdController.webhookAction);
router.post(“/autoid/recipeaction”, authenticationMiddleware, autoIdController.recipeAction);

In autoIdController I have a function where I put you example code:

export async function webhookAction(req, res) {
const { challenge } = req.body;
console.log(req.body);
try {
if (challenge) return res.send({ challenge });
// Custom Logic
res.status(200).send();
} catch (e) {
console.log(e);
res.status(400).send();
}
}

The subscribe and unsubscribe endpoint are working fine. It looks like the webhookaction endpoint never receives the request (nothing in the console.log). Any ideas?

Thanks to @kamescg and amazing @dipro :slight_smile: I managed to get this working. The webhook post (including the initial challenge) does not contain the app signing secret and therefore the authenticationMiddleware will reject the request.

Modified:
router.post("/autoid/webhookaction", authenticationMiddleware, autoIdController.webhookAction);
To:
router.post("/autoid/webhookaction", autoIdController.webhookAction);

resolved the issue. My code inserts the webhook (create_item) that now posts to my endpoint.

1 Like

Hi @basdebruin

Can you tell how you are returning the challenge i am using this method but i am getting creation id —> null instead of webhook id.

exports.handler = async event => {
  console.log( {"challenge": JSON.parse(event.body).challenge});
  const response = {
    statusCode: 200,
    body: event.body
    
  };
  console.log(response);
  return response;
};

Can you help me out?

Hi @krishna

Not sure I fully understand your question. How did you create the webhook on your board, is it by code or through the UI? Are you sure the webhook is fired and how does the event look like? If there is no challenge in the event apparently the monday side (where the webhook gets triggered) already “trust” your side (where you process the request) and you can use the data in the event. The challenge handshake will only take place on the first request generated by the triggered webhook.

Does that make sense?

Thanks for the reply @basdebruin

I am trying to create webhook using API v2 mutation request,So while registering they will send a challenge to our endpoint to verify ,we need to return it back as repsonse.

I am returning the response but webhook is not getting created and it is returning null instead of webhook id.

Hi @krishna

How does the very first event you get look like? Does it contain a challenge at all?

This is how i tried to register

mutation{ create_webhook(board_id:XXXXX, url:CUSTOM_URL event: change_column_value ) {id}}

then they sent a challenge to the custom url for verification
{challenge:SOME_CODE}
Now for successful creation of webhook we need to return this challenge from our CUSTOM_URL

I did that using this function

exports.handler = async event => {
  console.log( {"challenge": JSON.parse(event.body).challenge});
  const response = {
    statusCode: 200,
    body: event.body
    
  };
  console.log(response);
  return response;
};

But even after doing all of this i am getting this

{
  "data": {
    "create_webhook": null
  },
  "account_id": 123123123
}

So you got the challenge in the first request? Looks like your are returning the full body.event as a response, where monday only expects the challenge (req.body.challenge). Therefore you always need to do something like this:

  • check if there is a challenge in the request
    – if so, return the challenge (not the full body)
    –if not, do whatever you want with the event

Thank you so much @basdebruin It worked :blush:.I was sending whole body that was the reason why i was getting null instead of webhook id.

2 Likes