Cannot link Manager and customer account using mutateLink

75 views
Skip to first unread message

Amrender kumar

unread,
Oct 10, 2017, 12:26:28 PM10/10/17
to AdWords API Forum

Hi guys,
In one of my projects, I am trying to link a Manager account with a customer (My account) account but it throws following error:
Fatal error: Uncaught exception 'Google\AdsApi\AdWords\v201705\cm\ApiException' with message '[ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]

I have manager account id 9663159860 and customerId 6694378287. In the first step, I am taking refresh token by following oauth2 steps and getting the customer ID. After that, I am passing the customerID in ManagedCustomerLink object but when I try to use mutateLink it throws the above error. Here is the code below which I have used assuming I have already set the refresh token of customer in ini file.

public static function runExample(AdWordsServices $adWordsServices,
AdWordsSession $session) {
//$campaignService = $adWordsServices->get($session, CampaignService::class);
$managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class);

$customer = new ManagedCustomerLink();
$customer->setManagerCustomerId("9663159860");
$customer->setClientCustomerId("6694378287");
$customer->setLinkStatus("PENDING");
 

// Create operation.
$operation = new LinkOperation();
$operation->setOperand($customer); 
$operation->setOperator("ADD"); 

 
//$operation->OperationType = $OperationType;

$operations = array($operation);

echo '<pre>';
print_r($operations);

// Make the mutate request.
$result = $managedCustomerService->mutateLink($operations);

print_r($result);
exit;
}

I would appreciate anyone's help as I am stuck for several hours here.


Thanks,
Amrender

MWA

unread,
Oct 13, 2017, 9:05:57 AM10/13/17
to AdWords API Forum

Use this code:
$link = new ManagedCustomerLink();
$link->setManagerCustomerId($managerid);
$link->setClientCustomerId($customerid);
$link->setLinkStatus(LinkStatus::PENDING);

$linkop = new LinkOperation();    
$linkop->setOperator(Operator::ADD);
$linkop->setOperand($link);

$operations = array($linkop);

$result = $managedCustomerService->mutateLink($operations);
Reply all
Reply to author
Forward
0 new messages