0
votes

I am trying to link an Adwords Account to MCC Account using Node Adwords NPM Package

  1. I have MANAGER/Admin Access to Both Accounts (not same email)
  2. I created a project/application on google console developer to get
    Client_ID and Client_Secret using MCC Email User.
  3. I recovered Access Token/Refresh Token using the above credentials
  4. Now using a production developer token with Standard Access, Client_ID, Client_Secret, Refresh_Token, Access_Token and ClientCustomerID

I get the Refresh Token using Passport OAuth2 SSO process.

The client should login through our web app, once successfully logged in we receive his access_token & refresh_token, then we invite him to be managed by our MCC account, however the request fails and says unauthorized.

What Am I doing wrong ?

1-SOAP Response

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <ns2:ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/mcm/v201802" xmlns="https://adwords.google.com/api/adwords/cm/v201802">
         <requestId>000579c3b56e65c00a85859ae60c1a37</requestId>
         <serviceName>ManagedCustomerService</serviceName>
         <methodName>mutateLink</methodName>
         <operations>1</operations>
         <responseTime>173</responseTime>
      </ns2:ResponseHeader>
   </soap:Header>
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>[ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]</faultstring>
         <detail>
            <ns2:ApiExceptionFault xmlns:ns2="https://adwords.google.com/api/adwords/mcm/v201802" xmlns="https://adwords.google.com/api/adwords/cm/v201802">
               <message>[ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]</message>
               <ApplicationException.Type>ApiException</ApplicationException.Type>
               <errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManagedCustomerServiceError">
                  <fieldPath>operations[0]</fieldPath>
                  <fieldPathElements>
                     <field>operations</field>
                     <index>0</index>
                  </fieldPathElements>
                  <trigger />
                  <errorString>ManagedCustomerServiceError.NOT_AUTHORIZED</errorString>
                  <ApiError.Type>ManagedCustomerServiceError</ApiError.Type>
                  <ns2:reason>NOT_AUTHORIZED</ns2:reason>
               </errors>
            </ns2:ApiExceptionFault>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

2- Node Sample Code

const adwordsUser = new AdwordsUser({
            developerToken: 'DEVToken',
            userAgent: 'App Name',
            client_id: 'CLIENT_ID',
            client_secret: 'CLIENT_SECRET',
            refresh_token: 'REFRESH_TOKEN',
            clientCustomerId: 'AdwordsAccountID'
        });
        customerService = adwordsUser.getService('ManagedCustomerService', null);

    customerService.mutateLink({
        operations: [
            {
                operator: 'ADD',
                operand: {
                    managerCustomerId: 'MCCAccountCustomerID',
                    clientCustomerId: 'AdwordsAccountID',
                    linkStatus: 'PENDING'
                }
            }
        ]
    }, function (err, result) {
        if (err) console.log(err)
        console.log(result)
    })
1

1 Answers

0
votes

To send an invitation to an adwords account from MCC:

  1. You have to create a client_id and client_secret with the same admin/manager in your MCC

  2. Generate OAuth2 tokens with the same user with adwords scope (Manager of your MCC)

  3. Make your call with your MCC Account (You can use developer token from any MCC, it doesn't matter)

  const adwordsUser = new AdwordsUser({
        developerToken: 'DEVToken',
        userAgent: 'App Name',
        client_id: 'CLIENT_ID',
        client_secret: 'CLIENT_SECRET',
        refresh_token: 'REFRESH_TOKEN',
    });
 adwordsUser.credentials.clientCustomerId = 'MCCAccountCustomerID';
 customerService = adwordsUser.getService('ManagedCustomerService', null);
 operations: [{
                    operator: 'ADD',
                    operand: {
                        managerCustomerId: 'MCCAccountCustomerID',
                        clientCustomerId: 'AdwordsAccountID', // Account to invite
                        linkStatus: 'PENDING'
                    }
                }]

To accept an invitation in clients account:

  1. Generate OAuth2 tokens with client user

  2. Make the call with the client's adwords account, active link status, and SET as operator

const adwordsUser = new AdwordsUser({
        developerToken: 'DEVToken',
        userAgent: 'App Name',
        client_id: 'CLIENT_ID',
        client_secret: 'CLIENT_SECRET',
        refresh_token: 'REFRESH_TOKEN',
    });
 adwordsUser.credentials.clientCustomerId = 'AdwordsAccountID'; // invited account id
 customerService = adwordsUser.getService('ManagedCustomerService', null);
 operations: [{
                operator: 'SET',
                operand: {
                    managerCustomerId: 'MCCAccountCustomerID',
                    clientCustomerId: 'AdwordsAccountID',
                    linkStatus: 'ACTIVE'
                }
            }]