C# access to Generate Forecast Metrics

91 views
Skip to first unread message

Bruce Axtens

unread,
Jul 31, 2023, 12:51:05 AM7/31/23
to Google Ads API and AdWords API Forum
As can be seen in the current (2023-07-31) documentation <https://developers.google.com/google-ads/api/docs/keyword-planning/generate-forecast-metrics>, there's currently no C# demo code. I've been trying to work it out anyway and am getting very close. However, I've hit a snag.

I've done the OAuth2 without difficulty. When I come to the actual GenerateKeywordForecastMetrics request I get the following error: "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"

I have checked and re-checked that I have the correct login-customer-id. I have enabled trace via  
                TraceUtilities.Configure(
                    TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
                    $@"C:\logs\{Me}_{DateTime.Now:yyyy'-'MM'-'dd'-'HH'-'mm'-'ss'-'ff}_trace.log",
                    System.Diagnostics.SourceLevels.All);
and the output is clearly showing that the login-customer-id is being correctly supplied.

Am currently clueless on how to progress. Helpful suggestions welcome.

-Bruce

Google Ads API Forum Advisor

unread,
Jul 31, 2023, 4:32:32 AM7/31/23
to bru...@searchsmart.com.au, adwor...@googlegroups.com

Hi Bruce,

Thank you for reaching out to Google Ads API Forum.

I can see that you have encountered the USER_PERMISSION_DENIED error. This error usually indicates that the authorized customer does not have access to the operating customer.

That being said, you will need to ensure that the user / email address you used to generate the OAuth2 credentials indeed has access to the account in your request. If the user / email address has access or is associated with the MCC / manager account, you will need to specify the MCC / manager account's ID without hyphens (-) as the value of the login-customer-id field.

Let us know how it goes on your end if this resolves your issue. If the error persists after trying the suggested solution, then you may provide to us the updated complete API logs (request and response with request-id and request header) generated when you encountered the said error along with the email address used to generate the OAuth2 credentials from your end so we can investigate further. You can provide it via the Reply privately to author option. If this option is not available, then send it instead on this email address googleadsa...@google.com.

Reference links included in this email:

 

This message is in relation to case "ref:_00D1U1174p._5004Q2mxRvV:ref"

Thanks,
 
Google Logo Google Ads API Team


Bruce Axtens

unread,
Jul 31, 2023, 5:34:57 AM7/31/23
to Google Ads API and AdWords API Forum
Okay that appeared to have fixed one problem. It was the email address used. Now I've got a different problem. The error "Request contains an invalid argument." is a tad ambiguous. A JSON serialization of the error object's Failure property includes '"KeywordPlanIdeaError": 3,"HasKeywordPlanIdeaError": true,' which is also a little ambiguous.

-Bruce

GoogleAds.DetailedRequestLogs Information: 1 : [2023-07-31 09:27:02Z] -
---------------BEGIN API CALL---------------

Request
-------

Method Name: /google.ads.googleads.v14.services.KeywordPlanIdeaService/GenerateKeywordForecastMetrics
Host:
Headers: {
  "x-goog-api-client": "gl-dotnet/4.8.1 gapic/16.1.0 gax/4.2.0+a8085e4f36ad24e2747b5e550f11079d4a891e78 grpc/2.46.3 gccl/3.0.0 pb/3.21.5+638779f353731a0a04496bde20d14164684c3d93",
  "developer-token": "REDACTED",
  "login-customer-id": "2963060815",
  "x-goog-request-params": "customer_id=7415265454"
}

{ "customerId": "7415265454", "forecastPeriod": { "startDate": "2023-08-30", "endDate": "2023-09-30" }, "campaign": { "languageConstants": [ "languageConstants/1000" ], "geoModifiers": [ { "geoTargetConstant": "geoTargetConstants/2826" } ], "keywordPlanNetwork": "GOOGLE_SEARCH", "biddingStrategy": { "manualCpcBiddingStrategy": { "dailyBudgetMicros": "100000000000", "maxCpcBidMicros": "500000000" } }, "conversionRate": 0, "adGroups": [ { "maxCpcBidMicros": "10000000000", "biddableKeywords": [ { "keyword": { "matchType": "EXACT", "text": "workforce management software" }, "maxCpcBidMicros": "100000000000" } ] } ] } }

Response
--------
Headers: {
  "request-id": "K-2AVmTo4IfEsdJz1ADL9g",
  "date": "Mon, 31 Jul 2023 09:27:01 GMT",
  "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
  "google.ads.googleads.v14.errors.googleadsfailure-bin": "CiYKA+AEAxIfVGhlIGlucHV0IGhhcyBhbiBpbnZhbGlkIHZhbHVlLhIWSy0yQVZtVG80SWZFc2RKejFBREw5Zw==",
  "grpc-status-details-bin": "CAMSJVJlcXVlc3QgY29udGFpbnMgYW4gaW52YWxpZCBhcmd1bWVudC4aiAEKRHR5cGUuZ29vZ2xlYXBpcy5jb20vZ29vZ2xlLmFkcy5nb29nbGVhZHMudjE0LmVycm9ycy5Hb29nbGVBZHNGYWlsdXJlEkAKJgoD4AQDEh9UaGUgaW5wdXQgaGFzIGFuIGludmFsaWQgdmFsdWUuEhZLLTJBVm1UbzRJZkVzZEp6MUFETDln"
}

Fault: {
  "StatusCode": 3,
  "Details": "Request contains an invalid argument.",
  "RequestId": "K-2AVmTo4IfEsdJz1ADL9g",
  "Failure": {
    "errors": [
      {
        "errorCode": {
          "keywordPlanIdeaError": "INVALID_VALUE"
        },
        "message": "The input has an invalid value."
      }
    ],
    "requestId": "K-2AVmTo4IfEsdJz1ADL9g"
  }
}
----------------END API CALL----------------

 

Google Ads API Forum Advisor

unread,
Jul 31, 2023, 11:13:33 AM7/31/23
to bru...@searchsmart.com.au, adwor...@googlegroups.com
Hi Bruce,

Thank you for returning to our team.

With regards to your new issue, I tried your request on my end and I also got the same error. That being said, I tried using different values and you may see and refer to the below request:
 
{
  "forecastPeriod": {
    "startDate": "2023-08-30",
    "endDate": "2023-09-30"
  },
  "campaign": {
    "languageConstants": [
      "languageConstants/1000"
    ],
    "geoModifiers": [
      {
        "geoTargetConstant": "geoTargetConstants/2826"
      }
    ],
    "keywordPlanNetwork": "GOOGLE_SEARCH",
    "biddingStrategy": {
      "manualCpcBiddingStrategy": {
        "dailyBudgetMicros": 1000000,
        "maxCpcBidMicros": 500000
      }
    },
    "conversionRate": 0.1,
    "adGroups": [
      {
        "maxCpcBidMicros": 2000000,
        "biddableKeywords": [
          {
            "keyword": {
              "matchType": "EXACT",
              "text": "workforce management software"
            },
            "maxCpcBidMicros": 1000000
          }
        ]
      }
    ]
  }
}

As you can notice, I used different values especially in the conversionRate (https://developers.google.com/google-ads/api/rest/reference/rest/v14/customers/generateKeywordForecastMetrics#campaigntoforecast:~:text=campaign%20to%20forecast.-,conversionRate,0.02.%20If%20left%20empty%2C%20an%20estimated%20conversion%20rate%20will%20be%20used.,-CriterionBidModifier) field. Please note that this field is the expected conversion rate (number of conversions divided by number of total clicks) as defined by the user. This value is expressed as a decimal value, so an expected conversion rate of 2% should be entered as 0.02. If left empty, an estimated conversion rate will be used.

Let us know how it goes on your end.

Bruce Axtens

unread,
Jul 31, 2023, 10:49:34 PM7/31/23
to Google Ads API and AdWords API Forum
All fixed. Works a treat now. Thank you!

-Bruce

Reply all
Reply to author
Forward
0 new messages