ListInvoicesResponse error

121 views
Skip to first unread message

Siddhesh Deo

unread,
Feb 3, 2020, 5:55:55 AM2/3/20
to AdWords API and Google Ads API Forum
I need details of invoice so i have written code like below, 


But While getting response it is giving me an error.

ERROR:
Google.Ads.GoogleAds.V2.Errors.GoogleAdsException: 'Status(StatusCode=PermissionDenied, Detail="The caller does not have permission")'


CODE: 
string developerToken = "XXX";
            string oAuth2clientId = "XXX";
            string oAuth2Secret = "XXX";
            string oAuth2RefreshToken = "XXX";
            long loginCustomerId = long.Parse("XXX");

            GoogleAdsConfig googleAdsConfig = new GoogleAdsConfig()
            {
                DeveloperToken = developerToken,
                LoginCustomerId = loginCustomerId.ToString(),
                OAuth2ClientId = oAuth2clientId,
                OAuth2ClientSecret = oAuth2Secret,
                OAuth2RefreshToken = oAuth2RefreshToken,
            };

            GoogleAdsClient googleAdsClient = new GoogleAdsClient(googleAdsConfig);
            ListInvoicesRequest lstRequest = new ListInvoicesRequest();// googleAdsClient.GetService(Services.V2.Li session.GetService(Services.V2.CustomerService);
            lstRequest.CustomerId = "XXX"; //Acoount id for which the invoices request 
            lstRequest.BillingSetup = "XXX";
            lstRequest.IssueYear = "XXXX";
            lstRequest.IssueMonth = GoogleAds.V2.Enums.MonthOfYearEnum.Types.MonthOfYear.December;
            
            InvoiceServiceClient invService = googleAdsClient.GetService(Services.V2.InvoiceService);
            ListInvoicesResponse res = new ListInvoicesResponse();
            res = invService.ListInvoices(lstRequest);



Please help

Google Ads API Forum Advisor Prod

unread,
Feb 3, 2020, 2:07:53 PM2/3/20
to siddhe...@groupm.com, adwor...@googlegroups.com

Hi Siddhesh,

Thanks for reaching out. It is not a good idea to post the developer token and OAuth credentials in the forum as these information are highly sensitive so I would suggest you not to disclose them in the public place at any time in the future. As for your case, StatusCode=PermissionDenied indicates that the account you used to authenticate does not have the access to the customer account you are querying on. Specifically, you are using 5614642714 for both loginCustomerId  and CustomerId in the request. You would need to make sure the OAuth credentials were generated by an email address which has the Administrative access to account 5614642714. Also, you need to set a login-customer-id in your local configuration, please refer to this blog post on how to implement it. Please let me know if you have any further questions.

Thanks and regards,
Xiaoming, Google Ads API Team



 

ref:_00D1U1174p._5001UUzvvc:ref

Google Ads API Forum Advisor Prod

unread,
Feb 3, 2020, 2:12:01 PM2/3/20
to siddhe...@groupm.com, adwor...@googlegroups.com

Hi Siddhesh,

Thanks for reaching out. StatusCode=PermissionDenied indicates that the account you used to authenticate does not have the access to the customer account you are querying on. You would need to make sure the OAuth credentials were generated by an email address which has the Administrative access to the account you query on. Also, you need to  set a login-customer-id in your local configuration, please refer to this blog post on how to implement it. Please let me know if you have any further questions.



Thanks and regards,
Xiaoming, Google Ads API Team



 

ref:_00D1U1174p._5001UUzvwL:ref

Siddhesh Deo

unread,
Feb 4, 2020, 3:26:24 AM2/4/20
to AdWords API and Google Ads API Forum
Thanks for the prompt response, but we are still facing the same issue.

The OAuth credentials are generated by the account which has Admin access.
We have passed the MCC id in login-customer-id in App.config file
Also we have passed same MCC id in LoginCustomerId in App.config file, please find the sample below:

<add key = 'LoginCustomerId' value = 'XXXXXXXXXX' />
<add key = 'login-customer-id' value = 'XXXXXXXXXX' />


Please find the final code for fetching the billing details in Program.cs file of Google.Ads.GoogleAds.Examples:

            string developerToken = "XXXXXXXX";
            string oAuth2clientId = "YYYYYYY";
            string oAuth2Secret = "ZZZZZZZZ";
            string oAuth2RefreshToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            
            long loginCustomerId = long.Parse("XXXXXXX"); //MCC id with administrative access;

            GoogleAdsConfig googleAdsConfig = new GoogleAdsConfig()
            {
                DeveloperToken = developerToken,
                LoginCustomerId = loginCustomerId.ToString(),
                OAuth2ClientId = oAuth2clientId,
                OAuth2ClientSecret = oAuth2Secret,
                OAuth2RefreshToken = oAuth2RefreshToken,
            };

            GoogleAdsClient googleAdsClient = new GoogleAdsClient(googleAdsConfig);
            ListInvoicesRequest lstRequest = new ListInvoicesRequest();
            lstRequest.CustomerId = "1234567890"; //customer id of the account for which we need the invoice details;
            lstRequest.BillingSetup = "customers/1234567890/billingSetups/222222222";
            lstRequest.IssueYear = "2019";
            lstRequest.IssueMonth = GoogleAds.V2.Enums.MonthOfYearEnum.Types.MonthOfYear.December;

            InvoiceServiceClient invService = googleAdsClient.GetService(Services.V2.InvoiceService);
            ListInvoicesResponse res = new ListInvoicesResponse();
            res = invService.ListInvoices(lstRequest);


We are getting the same error 'Google.Ads.GoogleAds.V2.Errors.GoogleAdsException: 'Status(StatusCode=PermissionDenied, Detail="The caller does not have permission")'', please go through the code and let me know if we are following the same format and all the values passed are correct. While debugging I found that we are getting the error at the last line i.e. "res = invService.ListInvoices(lstRequest);"

Regards,
Siddhesh

Google Ads API Forum Advisor Prod

unread,
Feb 4, 2020, 1:26:15 PM2/4/20
to siddhe...@groupm.com, adwor...@googlegroups.com

Hi Siddhesh,

When you make an API call (with login-customer-id), you must specify the customer ID of a manager account that manages the Google Ads account for which you're requesting the invoice. In your case, you need to specify the login-customer-id with the customer ID of the manager account for 1234567890. Please refer to this documentation for more details. Please give it a try and if the issue persists, please send us the complete request and response logs along with the client customer Id and login-customer-id via Reply privately to author option.



Thanks and regards,
Xiaoming, Google Ads API Team



 

ref:_00D1U1174p._5001UUzvwL:ref
Reply all
Reply to author
Forward
0 new messages