Skip to main content

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

  • November 26, 2019
  • 14 replies
  • 4676 views

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?

This topic has been closed for replies.

14 replies

  • New Participant
  • November 28, 2019

+1
I experience the same problem.


  • Author
  • New Participant
  • December 3, 2019

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
}```

  • New Participant
  • December 4, 2019

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


basdebruin
  • Community Expert
  • July 29, 2020

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 🙂


kamescg
  • Participating Frequently
  • July 29, 2020

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();
  }
};

basdebruin
  • Community Expert
  • July 29, 2020

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?


basdebruin
  • Community Expert
  • July 30, 2020

Thanks to @kamescg and amazing @dipro 🙂 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.


  • Participating Frequently
  • August 7, 2020

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?


basdebruin
  • Community Expert
  • August 7, 2020

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?


  • Participating Frequently
  • August 7, 2020

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.


basdebruin
  • Community Expert
  • August 7, 2020

Hi @krishna

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


  • Participating Frequently
  • August 7, 2020

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
}

basdebruin
  • Community Expert
  • August 7, 2020

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

  • Participating Frequently
  • August 7, 2020

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