from __future__ import absolute_import
import argparseimport sysimport osimport six
import google.ads.google_ads.client
os.environ['https_proxy'] = 'https_proxy8'
GG_DEVELOP_TOKEN = "GG_DEVELOP_TOKEN "
credentials_dict_bv = {"token_uri": "https://oauth2.googleapis.com/token", "token": None, "scopes": ["https://www.googleapis.com/auth/adwords", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "openid"], "client_id": "7545454xxxx934-aol074ktdv9tb5435xxxxnrk4v368sq.apps.googleusercontent.com", "refresh_token": "1/jqqxxxSYHMDXdB8ABIxxxxxKzwDq-zEf8", "client_secret": "LxxxYC0q6VxxxxYsED"}
def main(client, customer_id, billing_setup_id): account_budget_proposal_service = client.get_service( 'AccountBudgetProposalService') billing_setup_service = client.get_service('BillingSetupService', version='v2')
account_budget_proposal_operation = client.get_type( 'AccountBudgetProposalOperation') proposal = account_budget_proposal_operation.create
proposal.proposal_type = client.get_type( 'AccountBudgetProposalTypeEnum').CREATE proposal.billing_setup.value = billing_setup_service.billing_setup_path( customer_id, billing_setup_id) proposal.proposed_name.value = 'Account Budget Proposal (example)'
# Specify the account budget starts immediately proposal.proposed_start_time_type = client.get_type('TimeTypeEnum', version='v2').NOW # Alternatively you can specify a specific start time. Refer to the # AccountBudgetProposal resource documentation for allowed formats. # # proposal.proposed_start_date_time = '2020-01-02 03:04:05'
# Specify that the budget runs forever proposal.proposed_end_time_type = client.get_type('TimeTypeEnum', version='v2').FOREVER # Alternatively you can specify a specific end time. Allowed formats are as # above. # # proposal.proposed_end_date_time = '2021-01-02 03:04:05'
# Optional: set notes for the budget. These are free text and do not effect # budget delivery. # # proposal.proposed_notes = client.wrapper # .string('Received prepayment of $0.01') proposal.proposed_spending_limit_micros.value = 0
try: account_budget_proposal_response = ( account_budget_proposal_service.mutate_account_budget_proposal( customer_id, account_budget_proposal_operation))
except google.ads.google_ads.errors.GoogleAdsException as ex: import pprint pprint.pprint(ex) print('Request with ID "%s" failed with status "%s" and includes the ' 'following errors:' % (ex.request_id, ex.error.code().name)) for error in ex.failure.errors: print('\tError with message "%s".' % error.message) if error.location: for field_path_element in error.location.field_path_elements: print('\t\tOn field: %s' % field_path_element.field_name) sys.exit(1)
print('Created account budget proposal "%s".' % account_budget_proposal_response.result.resource_name)
if __name__ == '__main__': # GoogleAdsClient will read the google-ads.yaml configuration file in the # home directory if none is specified. credentials = google.oauth2.credentials.Credentials(**credentials_dict_bv) client = google.ads.google_ads.client.GoogleAdsClient(credentials, GG_DEVELOP_TOKEN, login_customer_id='58564568752')
parser = argparse.ArgumentParser( description='Creates an account budget proposal.') # The following argument(s) should be provided to run the example. parser.add_argument('-c', '--customer_id', type=six.text_type, required=True, help='The Ads customer ID.') parser.add_argument('-b', '--billing_setup_id', type=six.text_type, required=True, help='The billing setup ID.') args = parser.parse_args()
main(client, args.customer_id, args.billing_setup_id)
/MutateAccountBudgetProposal, RequestId: mHN4Q6gXp1pAD5SJ1zdSfg, IsFault: True, FaultMessage: Resource was not found.GoogleAdsException(<_Rendezvous of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Request contains an invalid argument." debug_error_string = "{"created":"@1568260765.293884322","description":"Error received from peer ipv4:10.0.0.19:8118","file":"src/core/lib/sur face/call.cc","file_line":1052,"grpc_message":"Request contains an invalid argument.","grpc_status":3}">, <_Rendezvous of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Request contains an invalid argument." debug_error_string = "{"created":"@1568260765.293884322","description":"Error received from peer ipv4:10.0.0.19:8118","file":"src/core/lib/sur face/call.cc","file_line":1052,"grpc_message":"Request contains an invalid argument.","grpc_status":3}">, errors { error_code { mutate_error: RESOURCE_NOT_FOUND } message: "Resource was not found." location { field_path_elements { field_name: "operation" } field_path_elements { field_name: "create" } field_path_elements { field_name: "billing_setup" } }}, 'mHN4Q6gXp1pAD5SJ1zdSfg')Request with ID "mHN4Q6gXp1pAD5SJ1zdSfg" failed with status "INVALID_ARGUMENT" and includes the following errors: Error with message "Resource was not found.". On field: operation On field: create On field: billing_setup(google_test) [jiamin@domob-206 test_01]$ python add_account_budget.py -c 9834324964 -b 497361765Request made: ClientCustomerId: 9834324964, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v2.services.AccountBudgetProposalService /MutateAccountBudgetProposal, RequestId: Forr5vN5cGRCNA3g6epzRg, IsFault: True, FaultMessage: Resource was not found.GoogleAdsException(<_Rendezvous of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Request contains an invalid argument." debug_error_string = "{"created":"@1568260826.213461575","description":"Error received from peer ipv4:10.0.0.19:8118","file":"src/core/lib/sur face/call.cc","file_line":1052,"grpc_message":"Request contains an invalid argument.","grpc_status":3}">, <_Rendezvous of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Request contains an invalid argument." debug_error_string = "{"created":"@1568260826.213461575","description":"Error received from peer ipv4:10.0.0.19:8118","file":"src/core/lib/sur face/call.cc","file_line":1052,"grpc_message":"Request contains an invalid argument.","grpc_status":3}">, errors { error_code { mutate_error: RESOURCE_NOT_FOUND } message: "Resource was not found." location { field_path_elements { field_name: "operation" } field_path_elements { field_name: "create" } field_path_elements { field_name: "billing_setup" } }}, 'Forr5vN5cGRCNA3g6epzRg')Request with ID "Forr5vN5cGRCNA3g6epzRg" failed with status "INVALID_ARGUMENT" and includes the following errors: Error with message "Resource was not found.". On field: operation On field: create On field: billing_setup
Hi Jia,
Thank you for reaching out. Could you please make sure if you are providing a valid billing set up id while adding account budget proposal? The billing setup is associated with a payments account and the resource name for the billing set up must be in below format.
customers/{customer_id}/billingSetups/{billing_setup_id}
You might find this guide useful while adding account budget using BillingSetupService. Please give this a try and let me know if this helps. If the issue still persists, could you please share the complete request and response logs along with the client customer id for me to investigate further? Please use Reply privately to author option while sharing the information.
Regards,
Nikisha Patel, Google Ads API Team