Re: link mcc to ads account using rest interface

2024-05-16 Thread Tomas Maccarone
Hi,
Thanks for getting back to me. I understand, I added the fields which I 
believe were required but I'm still getting the same error, am I missing 
another field?
export async function createAccountLink(
managerCustomerId,
clientCustomerId,
managerAccessToken
) {
const url = `https://googleads.googleapis.com/v16/customers/${
managerCustomerId}/accountLinks:create`;

// The payload for the POST request
const body = {
accountLink: {
type: "UNKNOWN",
status: "PENDING_APPROVAL",
resourceName: `customers/${clientCustomerId}`,
},
};

try {
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${managerAccessToken}`, // Bearer token for the 
client account
"Developer-Token": process.env.GOOGLE_DEV_TOKEN, // Developer token for API 
access
"Content-Type": "application/json",
"login-customer-id": managerCustomerId, // Manager account ID
},
body: JSON.stringify(body), // Converting the payload to a JSON string
});

if (!response.ok) {
const responseText = await response.text();
console.error(
`Failed to create account link, status: ${response.status}, response: ${
responseText}`
);
throw new Error(
`API call failed with status ${response.status}: ${responseText}`
);
}

const data = await response.json();
console.log("Created Account Link:", data);
return data;
} catch (error) {
console.error("Failed to create account link:", error);
throw error;
}
}

I set type to "UNKNOWN" which is the one I believe it's correct following 
the available account types from this section: 
https://developers.google.com/google-ads/api/rest/reference/rest/v16/AccountLink#linkedaccounttype

I'm getting the following error:
Error: API call failed with status 400: {
  "error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
  {
"@type": 
"type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure",
"errors": [
  {
"errorCode": {
  "fieldError": "REQUIRED"
},
"message": "The required field was not present.",
"location": {}
  }
],

what field am I missing?

I'm trying to connect an MCC to a Google Ads account. managerCustomerId to 
clientCustomerId

Thanks for the help!
On Thursday, May 16, 2024 at 12:58:08 AM UTC-3 Google Ads API Forum Advisor 
wrote:

> Hi,
>
> Thank you for reaching out to the Google Ads API support team.
>
> Kindly note that the code you provided is missing some key fields in the 
> request body for creating an account link using the Google Ads API 
> . The missing 
> filed is a type which specifies the type of link being created. While the 
> code includes this information in the headers, it's also recommended to 
> include it in the request body for clarity. I would recommend you refer to 
> the documents AccountLink 
> ,
>  
> Linking product accounts 
> 
>  and Linking to Manager Accounts 
> 
>  to 
> get more information. Please go through the help center article Create a 
> Google Ads manager account 
>  for more 
> details.
>
> I hope this helps. Kindly get back to us if you have any further queries.
>   
> This message is in relation to case 
> "ref:!00D1U01174p.!5004Q02tIzNw:ref" (ADR-00235173)
>
> Thanks,
>   
> [image: Google Logo] Google Ads API Team 
>
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/c9092c87-5965-45d8-b8c2-cfe7929a53d2n%40googlegroups.com.


Link MCC to Ads account using REST interface

2024-05-15 Thread Tomas Maccarone
Hi,
Im trying to connect an MCC account to a Google Ads account following the 
following 
link 
https://developers.google.com/google-ads/api/rest/reference/rest/v16/customers.accountLinks/create

export async function createAccountLink(
managerCustomerId,
clientCustomerId,
clientAccessToken
) {
const url = `https://googleads.googleapis.com/v16/customers/${
managerCustomerId}/accountLinks:create`;

// The payload for the POST request
const body = {
accountLink: {
status: "PENDING_APPROVAL",
},
};

try {
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${clientAccessToken}`, // Bearer token for the 
client account
"Developer-Token": process.env.GOOGLE_DEV_TOKEN, // Developer token for API 
access
"Content-Type": "application/json",
"login-customer-id": managerCustomerId, // Manager account ID
},
body: JSON.stringify(body), // Converting the payload to a JSON string
});

if (!response.ok) {
const responseText = await response.text();
console.error(
`Failed to create account link, status: ${response.status}, response: ${
responseText}`
);
throw new Error(
`API call failed with status ${response.status}: ${responseText}`
);
}

const data = await response.json();
console.log("Created Account Link:", data);
return data;
} catch (error) {
console.error("Failed to create account link:", error);
throw error;
}
}

I believe I'm missing fields in the body request but I do not understand 
which ones are required. Do I need to add "type"? What would be the value? 
"Unknown"? I also couldn't find where to add the CID for the account I'm 
trying to connect. 

Looking for some guidance here. Appreciate the help!
Thanks!

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/c78d7622-c531-47c9-b3a1-a0121c3516a9n%40googlegroups.com.