Axios - Node js - 401 error - ads api

545 views
Skip to first unread message

Naveen DAVULURI

unread,
Mar 24, 2022, 8:46:04 AM3/24/22
to Google Ads API and AdWords API Forum
Team,

I am unable pull any campaign or any other information though axios post call.

here is my my code

const axios = require("axios");

const axiosApi = async () => {
  try {
    const accessTokenObj = await axios.post(
      new URLSearchParams({
        refresh_token: "REFRESH_TOKEN"  ,
        client_id: "CLIENT_ID",
      client_secret: "CLIENT_SECRET",
        grant_type: "refresh_token",
      }).toString()
    );
    return accessTokenObj.data.access_token;
  } catch (err) {
    console.log(err);
  }
};

With above code i am getting access_token , and passing it to below function to get the campaign details.

export const GoogleApi = async () => {
  const token = await axiosApi();

  try {
    const res = await axios
      .post(
        {
          headers: {
            Authorization: `Bearer ${token}`,
            "Content-Type": "application/json",
            "developer-Token": "9a0BmD37ug34fehYBT_2cw",
            "login-Customer-Id": "3965620957",
          },
        }
      )
      .then((resp) => console.log(resp));

    return res;
  } catch (error) {
    console.log(error);
  }
};

export default axiosApi;


i am getting the following error. (401)

 POST https://googleads.googleapis.com/v10/customers/3965620957/googleAds:searchStream 401
dispatchXhrRequest @ xhr.js?1a5c:210
xhrAdapter @ xhr.js?1a5c:15
dispatchRequest @ dispatchRequest.js?4dc9:58
request @ Axios.js?29fb:108
Axios.<computed> @ Axios.js?29fb:140
wrap @ bind.js?4bea:9
_callee$ @ axiosApi.js?7a34:27
tryCatch @ runtime.js?ecd4:45
invoke @ runtime.js?ecd4:274
prototype.<computed> @ runtime.js?ecd4:97
asyncGeneratorStep @ axiosApi.js:10
_next @ axiosApi.js:28
Promise.then (async)
asyncGeneratorStep @ axiosApi.js:19
_next @ axiosApi.js:28
eval @ axiosApi.js:33
eval @ axiosApi.js:25
GoogleApi @ axiosApi.js?7a34:22
Home @ index.tsx?07ff:28
renderWithHooks @ react-dom.development.js?ac89:14985
mountIndeterminateComponent @ react-dom.development.js?ac89:17883
beginWork @ react-dom.development.js?ac89:19049
beginWork$1 @ react-dom.development.js?ac89:23940
performUnitOfWork @ react-dom.development.js?ac89:22776
workLoopSync @ react-dom.development.js?ac89:22707
renderRootSync @ react-dom.development.js?ac89:22670
performSyncWorkOnRoot @ react-dom.development.js?ac89:22293
scheduleUpdateOnFiber @ react-dom.development.js?ac89:21881
updateContainer @ react-dom.development.js?ac89:25482
eval @ react-dom.development.js?ac89:26021
unbatchedUpdates @ react-dom.development.js?ac89:22431
legacyRenderSubtreeIntoContainer @ react-dom.development.js?ac89:26020
hydrate @ react-dom.development.js?ac89:26086
renderReactElement @ index.js?46cb:515
doRender @ index.js?46cb:831
_callee$ @ index.js?46cb:408
tryCatch @ runtime.js?ecd4:45
invoke @ runtime.js?ecd4:274
prototype.<computed> @ runtime.js?ecd4:97
asyncGeneratorStep @ index.js?46cb:30
_next @ index.js?46cb:48
eval @ index.js?46cb:53
eval @ index.js?46cb:45
_render @ index.js?46cb:427
render @ index.js?46cb:430
_callee$ @ index.js?46cb:394
tryCatch @ runtime.js?ecd4:45
invoke @ runtime.js?ecd4:274
prototype.<computed> @ runtime.js?ecd4:97
asyncGeneratorStep @ index.js?46cb:30
_next @ index.js?46cb:48
Promise.then (async)
asyncGeneratorStep @ index.js?46cb:39
_next @ index.js?46cb:48
Promise.then (async)
asyncGeneratorStep @ index.js?46cb:39
_next @ index.js?46cb:48
Promise.then (async)
asyncGeneratorStep @ index.js?46cb:39
_next @ index.js?46cb:48
eval @ index.js?46cb:53
eval @ index.js?46cb:45
_initNext @ index.js?46cb:396
initNext @ index.js?46cb:399
eval @ next-dev.js?3515:44
./node_modules/next/dist/client/next-dev.js @ main.js?ts=1648125085728:148
options.factory @ webpack.js?ts=1648125085728:606
__webpack_require__ @ webpack.js?ts=1648125085728:37
__webpack_exec__ @ main.js?ts=1648125085728:744
(anonymous) @ main.js?ts=1648125085728:745
webpackJsonpCallback @ webpack.js?ts=1648125085728:1152
(anonymous) @ main.js?ts=1648125085728:9
Show 20 more frames
axiosApi.js?7a34:42 Error: Request failed with status code 401
    at createError (createError.js?770c:16:1)
    at settle (settle.js?8768:17:1)
    at XMLHttpRequest.onloadend (xhr.js?1a5c:66:1)


Can someone help us on this please ?

Google Ads API Forum Advisor

unread,
Mar 24, 2022, 3:27:49 PM3/24/22
to nav...@adsiduous.com, adwor...@googlegroups.com
Hi Naveen,

Thank you for reaching out to the Google Ads API support team.

With regards to your cocncern,the Node.js framework isn't included to the list of our supported client libraries. However, in the Google Ads API's perspective, you can make use of the REST interface via this guide.

Thanks,
Google Logo
Nirmita
Google Ads API Team
 


ref:_00D1U1174p._5004Q2Yr2XP:ref
Reply all
Reply to author
Forward
0 new messages