InvalidArgument Statuscode when running example code

1,455 views
Skip to first unread message

Hoang Chu

unread,
Feb 22, 2021, 3:28:16 PM2/22/21
to AdWords API and Google Ads API Forum
Hi,

I get an InvalidArgument error when I tried this example code from the documentation page: https://developers.google.com/google-ads/api/docs/samples/generate-keyword-ideas

Here is the error message:
Google.Ads.GoogleAds.V6.Errors.GoogleAdsException: 'Status(StatusCode="InvalidArgument", Detail="Request contains an invalid argument.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1614025118.530000000","description":"Error received from peer ipv4:216.58.214.10:443","file":"..\..\..\src\core\lib\surface\call.cc","file_line":1063,"grpc_message":"Request contains an invalid argument.","grpc_status":3}")'

I'm using the .NET Core library Google.Ads.GoogleAds version 7.0. What am I doing wrong?




Google Ads API Forum Advisor Prod

unread,
Feb 23, 2021, 12:40:31 AM2/23/21
to hoan...@gmail.com, adwor...@googlegroups.com
Hi,

Could you provide the complete API request and response logs with request ID generated on your end where we can see the error to investigate it?

If you haven't enabled the logging of the API transactions for the specific client library that you are using, then please refer to the guide below:
Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2CTeXz:ref

Google Ads API Forum Advisor Prod

unread,
Feb 23, 2021, 9:58:19 PM2/23/21
to hoan...@gmail.com, adwor...@googlegroups.com
Hi,

Could you confirm if the issue is still occurring on your end? If yes, you can provide the complete API request and response logs with request ID generated on your end where we can see the error via Reply privately to author option to investigate it.

You may try to enable logging of the API transactions by following the guide below:

Hoang Chu

unread,
Mar 26, 2021, 9:02:51 AM3/26/21
to AdWords API and Google Ads API Forum

Hi,

Apology for the late response. That error disappeared since I updated the Google.Ads.GoogleAds library from version 6.1 to the recently release version 7.0.

However, instead of the original error I now get an USER_PERMISSION_DENIED error.

I'm trying this using a manager account (Access level: Test Account. ID: 584-763-xxxx) and a test account (ID: 106-298-xxxx) created under the manager account.
I've specified the test account ID (not manager account) as the LoginCustomerId and got the USER_PERMISSION_DENIED error.

However, when I used the manager count's ID as LoginCustomerId I get this error: DEVELOPER_TOKEN_NOT_APPROVED.

Which of the two account's ID should I use as LoginCustomerId? In my case either way get me (different) errors.

What am I doing wrong?

Below is the code to create a GoogleAdsConfig client.

public static GoogleAdsClient Create()
{
var settings = Startup.AppSettings.GoogleAdsApi;

var config = new GoogleAdsConfig
{
DeveloperToken = settings.DeveloperToken,
OAuth2Mode = OAuth2Flow.APPLICATION,
OAuth2ClientId = settings.OAuth2ClientId,
OAuth2ClientSecret = settings.OAuth2ClientSecret,
OAuth2RefreshToken = settings.OAuth2RefreshToken,
LoginCustomerId = settings.LoginCustomerId // ID of test account created under manager account: 106298xxxx
};
return new GoogleAdsClient(config);
}

Below is the example code I've used from the API documentation

public void Run(GoogleAdsClient client, string customerId, long[] locationIds, long languageId, string[] keywordTexts, string pageUrl)
{
var keywordPlanIdeaService = client.GetService(Services.V6.KeywordPlanIdeaService);

// Make sure that keywords and/or page URL were specified. The request must have
// exactly one of urlSeed, keywordSeed, or keywordAndUrlSeed set.
if (keywordTexts.Length == 0 && string.IsNullOrEmpty(pageUrl))
throw new ArgumentException("At least one of keywords or page URL is required, " +
"but neither was specified.");

// Specify the optional arguments of the request as a keywordSeed, UrlSeed,
// or KeywordAndUrlSeed.
var request = new GenerateKeywordIdeasRequest
{
CustomerId = customerId
};

if (keywordTexts.Length == 0)
{
// Only page URL was specified, so use a UrlSeed.
request.UrlSeed = new UrlSeed
{
Url = pageUrl
};
}
else if (string.IsNullOrEmpty(pageUrl))
{
// Only keywords were specified, so use a KeywordSeed.
request.KeywordSeed = new KeywordSeed();
request.KeywordSeed.Keywords.AddRange(keywordTexts);
}
else
{
// Both page URL and keywords were specified, so use a KeywordAndUrlSeed.
request.KeywordAndUrlSeed = new KeywordAndUrlSeed();
request.KeywordAndUrlSeed.Url = pageUrl;
request.KeywordAndUrlSeed.Keywords.AddRange(keywordTexts);
}


// Create a list of geo target constants based on the resource name of specified
// location IDs.
//   foreach (var locationId in locationIds)
//     request.GeoTargetConstants.Add(ResourceNames.GeoTargetConstant(locationId));

request.Language = ResourceNames.LanguageConstant(languageId);
// Set the network. To restrict to only Google Search, change the parameter below to
// KeywordPlanNetwork.GoogleSearch.
request.KeywordPlanNetwork = KeywordPlanNetworkEnum.Types.KeywordPlanNetwork.GoogleSearchAndPartners;

try
{
// Generate keyword ideas based on the specified parameters.
var response =
keywordPlanIdeaService.GenerateKeywordIdeas(request);

// Iterate over the results and print its detail.
foreach (var result in response)
{
var metrics = result.KeywordIdeaMetrics;
Console.WriteLine($"Keyword idea text '{result.Text}' has " +
  $"{metrics.AvgMonthlySearches} average monthly searches and competition " +
  $"is {metrics.Competition}.");
}
}
catch (GoogleAdsException e)
{
Console.WriteLine("Failure:");
Console.WriteLine($"Message: {e.Message}");
Console.WriteLine($"Failure: {e.Failure}");
Console.WriteLine($"Request ID: {e.RequestId}");
throw;
}
}

Google Ads API Forum Advisor Prod

unread,
Mar 28, 2021, 9:45:27 PM3/28/21
to hoan...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for the reply.

The USER_PERMISSION_DENIED error occurs when authenticating as a user with access to a manager account but not specifying login-customer-id in the request. With this, if the user account / email address you used to generate the Oauth2 credential has access to the manager account 584-763-xxxx, then it is correct to put its customer ID in the login-customer-id

For the DEVELOPER_TOKEN_NOT_APPROVED, this error occurs when you used a developer token that only has test account access level to the production account. However, since you said that it was just a test account, then could you confirm if this is the type of account you created for testing Google Ads API functionalities? If yes, then the error should not be encountered. That being said, could you provide the following details via Reply privately to author option to investigate:

Hoang Chu

unread,
Mar 29, 2021, 10:57:44 AM3/29/21
to AdWords API and Google Ads API Forum
I cannot see a link/button saying "Reply privately to author". I will post the details here in public anyway (as it's regarding test accounts).

Accounts details
Manager account ID: 584-763-1725 (this is a test account, not yet approved)
Customer account ID: 106-298-8633 (this is a test account created under the above manager account)

Output of the request and response
GoogleAds.DetailedRequestLogs Information: 1 : [2021-03-29 14:15:11Z] - 
---------------BEGIN API CALL---------------

Request
-------

Method Name: /google.ads.googleads.v6.services.KeywordPlanIdeaService/GenerateKeywordIdeas
Headers: {
  "x-goog-api-client": "gl-dotnet/3.1.0 gapic/7.0.0 gax/3.2.0+002f6637d17e4170f5db7ec7ca6f0163e6df1481 grpc/2.35.0",
  "developer-token": "REDACTED",
  "login-customer-id": "1062988633",
  "x-goog-request-params": "customer_id=1062988633"
}

{ "customerId": "1062988633", "keywordSeed": { "keywords": [ "ondernemen", "brexit", "corona" ] }, "keywordPlanNetwork": "GOOGLE_SEARCH_AND_PARTNERS", "language": "languageConstants/1010" }

Response
--------
Headers: {
  "request-id": "9TTCpoYXYbIWZVbeOyuhSQ",
  "date": "Mon, 29 Mar 2021 14:15:12 GMT",
  "alt-svc": "h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
  "google.ads.googleads.v6.errors.googleadsfailure-bin": "Cv8BCgJIAhL4AVVzZXIgZG9lc24ndCBoYXZlIHBlcm1pc3Npb24gdG8gYWNjZXNzIGN1c3RvbWVyLiBOb3RlOiBJZiB5b3UncmUgYWNjZXNzaW5nIGEgY2xpZW50IGN1c3RvbWVyLCB0aGUgbWFuYWdlcidzIGN1c3RvbWVyIGlkIG11c3QgYmUgc2V0IGluIHRoZSAnbG9naW4tY3VzdG9tZXItaWQnIGhlYWRlci4gU2VlIGh0dHBzOi8vZGV2ZWxvcGVycy5nb29nbGUuY29tL2dvb2dsZS1hZHMvYXBpL2RvY3MvY29uY2VwdHMvY2FsbC1zdHJ1Y3R1cmUjY2lk",
  "grpc-status-details-bin": "CAcSI1RoZSBjYWxsZXIgZG9lcyBub3QgaGF2ZSBwZXJtaXNzaW9uGsoCCkN0eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5hZHMuZ29vZ2xlYWRzLnY2LmVycm9ycy5Hb29nbGVBZHNGYWlsdXJlEoICCv8BCgJIAhL4AVVzZXIgZG9lc24ndCBoYXZlIHBlcm1pc3Npb24gdG8gYWNjZXNzIGN1c3RvbWVyLiBOb3RlOiBJZiB5b3UncmUgYWNjZXNzaW5nIGEgY2xpZW50IGN1c3RvbWVyLCB0aGUgbWFuYWdlcidzIGN1c3RvbWVyIGlkIG11c3QgYmUgc2V0IGluIHRoZSAnbG9naW4tY3VzdG9tZXItaWQnIGhlYWRlci4gU2VlIGh0dHBzOi8vZGV2ZWxvcGVycy5nb29nbGUuY29tL2dvb2dsZS1hZHMvYXBpL2RvY3MvY29uY2VwdHMvY2FsbC1zdHJ1Y3R1cmUjY2lk"
}

Fault: {
  "StatusCode": 7,
  "Details": "The caller does not have permission",
  "RequestId": "9TTCpoYXYbIWZVbeOyuhSQ",
  "Failure": {
    "errors": [
      {
        "errorCode": {
          "authorizationError": "USER_PERMISSION_DENIED"
        },
        "message": "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid"
      }
    ]
  }
}
----------------END API CALL----------------


Google Ads API Forum Advisor Prod

unread,
Mar 29, 2021, 3:28:05 PM3/29/21
to hoan...@gmail.com, adwor...@googlegroups.com
Hello,

Thanks for providing those details. I see that the child customer has bee specified as the login-customer-id. Can you please specify the manager ID, 584-763-1725, as the login-customer-id instead? 

So we can continue privately, please email us at googleadsa...@google.com and link this thread in your email for context. 

Thanks,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2CTeXz:ref

Hoang Chu

unread,
Mar 29, 2021, 4:34:56 PM3/29/21
to AdWords API and Google Ads API Forum
I'm getting a DEVELOPER_TOKEN_NOT_APPROVED error when I'm using the manager's ID as the login-customer-id. I've sent de log output to googleadsa...@google.com.

Thank you.

Reply all
Reply to author
Forward
0 new messages