# Auth failure when using Private App Key for HubDB calls.

**URL:** <https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235>\
**Category:** APIs & Integrations\
**Created:** [November 14, 2022, 5:49pm UTC](https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235 "2022-11-14T17:49:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCuadrado](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JCuadrado](https://community.hubspot.com/u/JCuadrado)\
**Post date:** [November 14, 2022, 5:49pm UTC](https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235/1 "2022-11-14T17:49:27Z")

</div>

I’m attempting to migrate from the hapikey to the private app key and this is the issue I’m encountering:

`{"message":{"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":"07a51d60-61f2-4489-acb5-68e238ddc67e","category":"INVALID_AUTHENTICATION"}}`

Here is the general code I’m using which has worked when I use the hapikey key:

```lia-code-sample
exports.main = ({body}, sendResponse) => {

 const postAPI = "https://api.hubspot.com/cms/v3/hubdb/tables/{{ table }}/rows/{{ row }}/draft;
 const widgetURL = "--------";

 axios
 .get(widgetURL)
 .then(function (response) {

 axios.
 patch(postAPI, {
 path: null,
 name: null,
 childTableId: 0,
 values: {
 "name": "widget",
 "json": JSON.stringify(JSON.stringify(response.data))
 },
 headers: { 
 'Authorization': 'Bearer {{ Private App Key Here }}', 

 },
 })
 .then(function(response) {
 console.log("HubDB table updated");
 console.log(response.data);
 console.log(response.status);

 sendResponse({
 statusCode: 200,
 body: {
 message: "HubDB table updated"
 }
 });
 })
 .catch(function(error) {
 // Log failure response of the HubDB table create row API call
 console.log("Failed to update HubDB table");
 console.log(error.response.data);
 console.log(error.response.status);

 // Send failure response that the dontaion was received
 sendResponse({
 statusCode: 500,
 body: {
 message: error.response.data
 }
 }); 
 })

 .catch(function(error) {
 console.log("Failed to get data");
 console.log(error.response.data);
 console.log(error.response.status);

 // Send failure response that the dontaion was received
 sendResponse({
 statusCode: 500,
 body: {
 message: error.response.data
 }
 }); 
 });
})
}

```

Is there something I’m doing wrong here?  
Thanks.

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [November 15, 2022, 6:30am UTC](https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235/2 "2022-11-15T06:30:30Z")

</div>

@JCuadrado

Hi.

Your code calles two API (GET `widget URL` and PATCH `post API`).

PATCH `post API` sets token, but GET `widget URL` isn’t set token.

so, GET `widget URL` has not credentials.

How about set token to GET `widget URL`?

```lia-code-sample
axios
.get(widgetURL, {
 // add `token`
 headers: { 
 'Authorization': 'Bearer {{ Private App Key Here }}', 

 },
})
.then(function (response) {

 axios.
 patch(postAPI, {
 path: null,
 name: null,
 childTableId: 0,
 values: {
 "name": "widget",
 "json": JSON.stringify(JSON.stringify(response.data))
 },
 headers: { 
 'Authorization': 'Bearer {{ Private App Key Here }}', 

 },
 })

```

Thanks.

---

<div class="post-metadata">

**Author:** ![JCuadrado](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JCuadrado](https://community.hubspot.com/u/JCuadrado)\
**Post date:** [November 15, 2022, 1:01pm UTC](https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235/3 "2022-11-15T13:01:48Z")

</div>

That’s because the widget api is calling a 3rd party api that requires no token. I realize that posting my entire code may have caused confusion. Here is a simplified version without the additional get call.

```lia-code-sample
exports.main = ({body}, sendResponse) => {

 const postAPI = "https://api.hubspot.com/cms/v3/hubdb/tables/{{my table}}/rows/{{my row}}/draft";

 axios.
 patch(postAPI, {
 path: null,
 name: null,
 childTableId: 0,
 values: {
 "name": "widget",
 "json": JSON.stringify(JSON.stringify(response.data))
 },
 headers: { 
 'Authorization': 'Bearer {{ Private App Key Here }}', 
 },
 })
 .then(function(response) {
 console.log("HubDB table updated");
 console.log(response.data);
 console.log(response.status);

 sendResponse({
 statusCode: 200,
 body: {
 message: "HubDB table updated"
 }
 });
 })
 .catch(function(error) {
 // Log failure response of the HubDB table create row API call
 console.log("Failed to update HubDB table");
 console.log(error.response.data);
 console.log(error.response.status);

 // Send failure response that the dontaion was received
 sendResponse({
 statusCode: 500,
 body: {
 message: error.response.data
 }
 }); 
 })

 }

```

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [November 16, 2022, 12:23am UTC](https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235/4 "2022-11-16T00:23:20Z")

</div>

\>That’s because the widget api is calling a 3rd party api that requires no token.

Oh, sorry.

How about this?

```lia-code-sample
axios.
 patch(postAPI, 
 {REQUEST BODY},
 { 
 headers: { 
 'Authorization': 'Bearer {{ Private App Key Here }}', 
 },
 })

```

> <https://stackoverflow.com/questions/53251044/axios-patch-on-feathersjs-no-auth-token>

---

<div class="post-metadata">

**Author:** ![JCuadrado](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JCuadrado](https://community.hubspot.com/u/JCuadrado)\
**Post date:** [November 16, 2022, 1:29pm UTC](https://community.hubspot.com/t/auth-failure-when-using-private-app-key-for-hubdb-calls/69235/5 "2022-11-16T13:29:26Z")

</div>

I changed up my header like you have above and it worked out. Thanks much skimura!
