⚙ Operations Hub

Yenma_H
Member

Error while using custom code trying to format US phone numbers

SOLVE

Hello! I could use your help. I am trying to use the custom code to update US phone numbers. I'm trying to use this code: https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/format_phone.js 

 

Unfortunately I'm getting an authentication issue, even though I have the proper access to the API key. I'm wondering if I'm missing something.

 

I would appreciate any insights or guidance.  Thank you so much!

 

Here is the error that I'm receiving: 

2022-03-30T21:30:42.009Z	ERROR	Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"HttpError: HTTP request failed","reason":{"errorType":"HttpError","errorMessage":"HTTP request failed","response":{"statusCode":401,"body":{"status":"error","message":"Authentication credentials not found. This API supports both API Key and OAuth 2.0 authentication and you can find more details at https://developers.hubspot.com/docs/methods/auth/oauth-overview","correlationId":"8e8cb121-ac32-4e5a-95fd-e571699295ab","category":"INVALID_AUTHENTICATION"},"headers":{"date":"Wed, 30 Mar 2022 21:30:41 GMT","content-type":"application/json;charset=utf-8","content-length":"316","connection":"close","cf-ray":"6f43f2abbc2a6f98-IAD","strict-transport-security":"max-age=31536000; includeSubDomains; preload","vary":"Accept-Encoding","cf-cache-status":"DYNAMIC","access-control-allow-credentials":"false","expect-ct":"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"","x-hubspot-correlation-id":"8e8cb121-ac32-4e5a-95fd-e571699295ab","x-trace":"2B800DF8395E017FB7199AB6DCE66490193D6717FB000000000000000000","report-to":"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=mddbyZg3j7FEMPQ2LdNrCqU1PRzsp0nj3E6LbmL6ovnBHOgq8nedgXyPe%2BMzrFpuZdastWD9doWHCtG6JdOXLMiYW8kqt6Edo%2BZ8FLgpSAOCCltfHAX47mBXYLBffrOn\"}],\"group\":\"cf-nel\",\"max_age\":604800}","nel":"{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}","server":"cloudflare","alt-svc":"h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.hubapi.com","port":null,"hostname":"api.hubapi.com","hash":null,"search":"?properties=phone","query":"properties=phone","pathname":"/crm/v3/objects/contacts/2926151","path":"/crm/v3/objects/contacts/2926151?properties=phone","href":"https://api.hubapi.com/crm/v3/objects/contacts/2926151?properties=phone"},"method":"GET","headers":{"User-Agent":"hubspot-api-client-nodejs; 3.4.1","Accept":"application/json"}}},"body":{},"statusCode":401,"name":"HttpError","stack":["HttpError: HTTP request failed","    at Request._callback (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/contacts/api/basicApi.js:318:40)","    at Request.self.callback (/opt/nodejs/node_modules/request/request.js:185:22)","    at Request.emit (events.js:314:20)","    at Request.<anonymous> (/opt/nodejs/node_modules/request/request.js:1154:10)","    at Request.emit (events.js:314:20)","    at IncomingMessage.<anonymous> (/opt/nodejs/node_modules/request/request.js:1076:12)","    at Object.onceWrapper (events.js:420:28)","    at IncomingMessage.emit (events.js:326:22)","    at endReadableNT (_stream_readable.js:1241:12)","    at processTicksAndRejections (internal/process/task_queues.js:84:21)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: HttpError: HTTP request failed","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:314:20)","    at processPromiseRejections (internal/process/promises.js:209:33)","    at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}

 

0 Upvotes
1 Accepted solution
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Error while using custom code trying to format US phone numbers

SOLVE

Hi @Yenma_H,

 

I tried to run the script on my end and I had the same authentication issue.
Here's how to troubleshoot :

  • Make sure you add the API key as a secret on your node
    LMeert_0-1649162308152.png

     

  • Also, you will have to change the name of the variable in the code line 13 :
    apiKey : process.end.HAPI_Key

And you should be good to go !

If this helped, consider marking this as a solution 🙂

Have a good day,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

View solution in original post

0 Upvotes
2 Replies 2
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Error while using custom code trying to format US phone numbers

SOLVE

Hi @Yenma_H,

 

I tried to run the script on my end and I had the same authentication issue.
Here's how to troubleshoot :

  • Make sure you add the API key as a secret on your node
    LMeert_0-1649162308152.png

     

  • Also, you will have to change the name of the variable in the code line 13 :
    apiKey : process.end.HAPI_Key

And you should be good to go !

If this helped, consider marking this as a solution 🙂

Have a good day,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

0 Upvotes
Yenma_H
Member

Error while using custom code trying to format US phone numbers

SOLVE

Thank you so much! I did end up figuring it out after some trial and error. This was the solution I used.  I appreciate your help!