APIs & Integrations

PCarlson
Participant

Create Task from Node JS library

SOLVE

I'm trying to create a task from an app using the NodeJS library.

 

My v3 api calls are working great using an OAuth token, but as I understand it, there are no engagement API calls yet in v3, so I'm trying to use the ApiRequest as described in the Not Wrapped Endpoints section to make the call described in the v1 legacy docs under Create An Engagement endpoint.

 

I get an HTTP request failed error calling that endpoint url using this code:

 

const apiOptions = {
  path: '/engagements/v1/engagements',
  method: 'POST',
  body: {
    engagement: {
      active: true,
      ownerId: ownerId,
      type: 'TASK',
      timestamp: activityDate, // timestamp is date due
    },
    associations: {
      contactIds: [ whoId ],
    },
    metadata: {
      body: description,
      subject: subject,
      status: status,
      forObjectType: 'CONTACT',
    }
  }
}
await this._client.apiRequest(apiOptions)
 
Anyone have any tips?
 
Some observations that raise questions for me:
  1. The library reference says to use 'path', the legacy docs say to use 'url'. I have found that 'path' works in other places, so I used 'path' above.
  2. The legacy docs do not go over using an oauth access token, but I believe this is wrapped by the nodejs library and the error says nothing about authorization. Do I need to include it as a qs paramater in options? With what parameter name?

Thanks

Phil

0 Upvotes
1 Accepted solution
PCarlson
Solution
Participant

Create Task from Node JS library

SOLVE

The secret seems to be passing a value for Status that is valid in the predefined list. More carefully reading https://legacydocs.hubspot.com/docs/methods/engagements/create_engagement, for a task it says:

 

 

The status needs to be NOT_STARTED, COMPLETED, IN_PROGRESS, WAITING, or DEFERRED.

 

 

When I carefully set Status using the literal "NOT_STARTED", the api call worked. So I have to be careful to only allow a status value from the pre-defined list.

 

More specifically, passing Status as an empty string causes the API call to fail. But note that passing Status as undefined appears to work.

 

Also note no access token is needed, so it appears the API takes care of that.

 

Phil

View solution in original post

3 Replies 3
PCarlson
Solution
Participant

Create Task from Node JS library

SOLVE

The secret seems to be passing a value for Status that is valid in the predefined list. More carefully reading https://legacydocs.hubspot.com/docs/methods/engagements/create_engagement, for a task it says:

 

 

The status needs to be NOT_STARTED, COMPLETED, IN_PROGRESS, WAITING, or DEFERRED.

 

 

When I carefully set Status using the literal "NOT_STARTED", the api call worked. So I have to be careful to only allow a status value from the pre-defined list.

 

More specifically, passing Status as an empty string causes the API call to fail. But note that passing Status as undefined appears to work.

 

Also note no access token is needed, so it appears the API takes care of that.

 

Phil

dennisedson
HubSpot Product Team
HubSpot Product Team

Create Task from Node JS library

SOLVE

Hey @PCarlson !

Are you still messing around with this?

@RMones , @AC-valo -- Do you all have any ideas about this one?

0 Upvotes
PCarlson
Participant

Create Task from Node JS library

SOLVE

Hi Dennis,

 

Yes, I'm still working on this. I'm a weekend warrior on this project, but I try to keep up on my posts in between.

 

Still not solved, but perhaps more info. I discovered the nodejs sample apps have a call that creates a task here. But it creates it by getting an existing engagement, cloning it and doing a set on the payload for start and end times. I'm creating a new task reflecting an exterior action, so there is no existing engagement for me to clone like this. But this might indicate I need to set the full structure of the engagement, so I'll play with that.

 

I also found json that shows the oauth access token using the Bearer tag unde qs, but I don't recall where I saw this. So I'll play with that as well.

 

Phil

0 Upvotes