creating webhook returns "You should specify one of resource" using nodejs client

Hi!, when I’m creating a webhook via curl it’s working:

curl -H "Authorization: Bearer <PAT TOKEN>" \
  -X POST https://app.asana.com/api/1.0/webhooks \
  -d "resource=PROJECT_GID" \
  -d "target=TARGET_URL"

but when i’m using nodejs it gave me error 400 even though I specified my resource ID:

require('dotenv').config();
const asana = require('asana');
...
const client = asana.Client.create().useAccessToken(personalAccessToken);

client.webhooks.createWebhook({
    body: {
      "data": {
        "resource": projectGID,
        "target": webhookTargetURL,
      }
    },
    pretty: true,
  }).then(result => {
    console.log(result);
  }).catch(err => {
    console.log(err.value.errors);
  });

and here’s the error:

InvalidRequest [Error]: Invalid Request
    at InvalidRequest.AsanaError (/home/user/webhooks/asana/node_modules/asana/lib/errors/error.js:4:11)
    at new InvalidRequest (/home/user/webhooks/asana/node_modules/asana/lib/errors/invalid_request.js:5:14)
    at Request._callback (/home/user/webhooks/asana/node_modules/asana/lib/dispatcher.js:263:23)
    at Request.self.callback (/home/user/webhooks/asana/node_modules/request/request.js:185:22)
    at Request.emit (node:events:390:28)
    at Request.<anonymous> (/home/user/webhooks/asana/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:390:28)
    at IncomingMessage.<anonymous> (/home/user/webhooks/asana/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:509:28)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  status: 400,
  value: { errors: [ [Object] ] }
}

I am not sure createWebhook expects a body and a data param. Can you try to give it { "resource": projectGID, "target": webhookTargetURL, } directly instead?

2 Likes

Hi @Bastien_Siebman thanks for helping me out :pray:

Passing directly resource and target definitely worked instead of copying based on the example body params in docs. Im confused why it says in the docs that body is required? or is it resource and target should be outside body param? here’s the screenshot:

It is confusing because you are reading the doc to make direct calls using curl for example but using the nodeJS lib, which integrates wrappers and has its own structure when it comes to params.

Put otherwise: body is created by the lib, you don’t have to take care of it.