BadHorse
BadHorse

Reputation: 21

How do I link accounts in the Google Adwords API using just a customer ID?

I'm having a very hard time understanding Google's API documentation and was hoping for some help here.

To me, as an extremely new developer, the Google API documentation makes no sense whatsoever.

I am using the google adwords Python library, and this code may be useful: https://github.com/googleads/googleads-python-lib/blob/b80b8b3741a55f1d00c5974bc58f92540663c6f6/examples/adwords/v201603/account_management/create_account.py. However, I need to link an already existing account by extending an invitation and marking it as pending. I'm not trying to create a new account.

So where do I begin with writing it in Python? I don't understand the documentation and just need to create an account based on a given customer ID. Any tips and tricks would be great!

Upvotes: 2

Views: 841

Answers (1)

dorian
dorian

Reputation: 6272

To link an existing account into your MCC account, you also need to use the ManagedCustomerService, specifically the mutateLink method. In Python, it would look something like this:

# Create the service object
managed_customer_service = client.GetService('ManagedCustomerService', version='v201605')

# Construct the operation, operator "ADD" and status "PENDING" results in a new invitation
operation = {
    'operator': 'ADD',
    'operand': {
        'managerCustomerId': YOUR_MCC_ACCOUNT_ID,
        'clientCustomerId': ACCOUNT_ID_TO_BE_INVITED,
        'linkStatus': 'PENDING',
        'pendingDescriptiveName': 'Some text that helps identifying the invitation',
        'isHidden': False  # This can be used to hide the account in your MCC to decrease clutter
    }
}

# Send the operation
response = managed_customer_service.mutateLink([operation])

# Print out the resulting ManagedCustomerLink
pprint.pprint(response.links[0])

Note that I didn't test this code, but it should give you a general idea on how it works. See the reference guide for more details and how to proceed once the client account has accepted the invitation.

Upvotes: 1

Related Questions