I am now looking to get invoice info using Google Ads API I tried to code the following and run it in GoogleAppScript, but all I got was an error message "Request contains an invalid argument.
const access_token = "XXXXXXXXXXXXXXXXXX";
const developer_token = "XXXXXXXXXXXXXXXXXX";
const mcc_account = "XXXXXXXXXX";
const customerId = "XXXXXXXXXXXXX";
const billing_Setup = "XXXXXXX";
const issue_Year = "2022";
function download_invoices(access_token, developer_token, mcc_account, customerId, billing_Setup, issue_Year) {
const billingSetup = encodeURIComponent(`customers/${customerId}/billingSetups/${billing_Setup}`);
const url = `https://googleads.googleapis.com/v10/customers/${customerId}/invoices?billingSetup=${billingSetup}&issueYear=${issue_Year}&issueMonth=MARCH`;
const headers = {
"Authorization": "Bearer " + access_token,
"developer-token": "Bearer " + developer_token,
"login-customer-id": "Bearer " + mcc_account
};
const options = {
"method": "get",
"headers": headers,
};
const httpResponse = UrlFetchApp.fetch(url, options);
const status = httpResponse.getResponseCode();
if (status !== 200) {
throw "HttpRequestError";
}
const response = JSON.parse(httpResponse.getContentText());
return response;
}
By the way, I am able to get the access token without any problem.
const client_Id = "XXXXXX";
const client_Secret = "XXXXXXXXXXXXXXXXXX";
const refresh_Token = "XXXXXXXXXXXXXXXXXX";
function get_accesstoken(client_Id, client_Secret, refresh_Token) {
const url = "https://accounts.google.com/o/oauth2/token";
const opt = {
"method" : "POST",
"payload" : {
"client_id" : client_Id,
"client_secret" : client_Secret,
"refresh_token" : refresh_Token,
"grant_type" : "refresh_token"
},
"muteHttpExceptions" : true
};
const httpResponse = UrlFetchApp.fetch(url, opt);
const status = httpResponse.getResponseCode();
if (status !== 200) {
throw 'HttpRequestError';
}
const response = JSON.parse(httpResponse.getContentText());
return response;
}
Is there something missing in this code?
All codes were made with the following reference.
Result : I thought I could get the invoice information tied to my account, but all I got was an error "Request contains an invalid argument.
Exception: Request failed for https://googleads.googleapis.com returned code 400. Truncated server response: {
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
... (use muteHttpExceptions option to examine full response)