I would like to query the number of conversions per click in a google adwords report using the SOAP API. Unfortuately the following query (Python),
# Create report definition.
report = {
'reportName': 'Last 30 days ADGROUP_PERFORMANCE_REPORT',
'dateRangeType': 'LAST_30_DAYS',
'reportType': 'ADGROUP_PERFORMANCE_REPORT',
'downloadFormat': 'CSV',
'selector': {
'fields': ['CampaignId', 'AdGroupId', 'Id',
'Impressions', 'Clicks', 'Cost',
'Conv1PerClick',
'CampaignName','AdGroupName']
},
# Enable to get rows with zero impressions.
'includeZeroImpressions': 'false'
}
results in the following error
AdWordsReportError: HTTP code: 400, type: 'ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT', trigger: 'Conv1PerClick', field path: ''
Google documentation (https://developers.google.com/adwords/api/docs/appendix/reports) seems to indicate that such a report should have a conv1PerClick field (I tryed also removing capitalization of the first letter, similar error occurs ).
Does anybody knows a way to query the ad group statistics about conversions per click?
Not sure if I am understanding you correctly, but the field is called Conversions, not Conv1PerClick. If you download the report in XML format, then the corresponding field attribute name used to be conv1PerClick, but this changed in v201402 in line with some changes to the way these metrics are computed:
http://adwords.blogspot.ch/2014/02/a-new-way-to-count-conversions-in.html
https://developers.google.com/adwords/api/docs/guides/migration/v201402
Related
I am trying to create a new custom object in Salesforce with two fields. The object is being created, but I am not able to write any records to it.
Acc to the error, the fields are not present in the object.
import pandas as pd
from simple_salesforce import Salesforce
sf = Salesforce(username='user', password='pass', security_token='token')
name = "CustomObject13__c"
label = "CO13"
md_api = sf.mdapi
custom_object = md_api.CustomObject(
fullName=name,
label=label,
pluralLabel="Custom Objects",
nameField=md_api.CustomField(
label="Name",
type=md_api.FieldType("Text")
),
fields=[{
'fullName': 'Age__c',
'label': 'Age',
'type': 'Text',
'length': 255
},
{
'fullName': 'Description__c',
'label': 'Description',
'type': 'TextArea'
}],
deploymentStatus=md_api.DeploymentStatus("Deployed"),
sharingModel=md_api.SharingModel("Read")
)
md_api.CustomObject.create(custom_object)
df = pd.DataFrame({'Name': ['Sal Vulcano', 'James Murray'], "Age__c": ["34", "54"],
"Description__c": ["tonight's big loser", "fool-proof plan"]})
for record in df.to_dict('records'):
sf.__getattr__(name).create(record)
ERROR:
simple_salesforce.exceptions.SalesforceMalformedRequest: Malformed request https://rawcubes-dev-ed.my.salesforce.com/services/data/v52.0/sobjects/CustomObject13__c/. Response content: [{'message': "No such column 'Age__c' on sobject of type CustomObject13__c", 'errorCode': 'INVALID_FIELD'}]
Object Manager - Fields and Relationships Viewer for the object 'CO13'
When you create a sObject (table in database) - it's there but doesn't automatically mean you can see it. As sysadmin you bypass some checks when administering the org (making changes in Setup) - but API access will still stop you.
You need to grant the right to Create, Edit on the Object itself + Edit right on every custom field you added. You do that by editing your profile or permission sets (or creating new permission set and assigning it to your user by inserting new record into PermissionSetAssignment table).
So it's few more metadata operations for you before you can insert data. Typically it'd be done separately, first create table (even manually), then load...
I'm trying to register a domain for customers using WHMCS apis with python.
The issue I'm having is with the additional domain fields, in this case for the .eu domain:
additional_domainfields = base64.b64encode(phpserialize.dumps({'Entity Type':'INDIVIDUAL', 'EU Country of Citizenship':'IT'}))
post_data = {
'identifier':'xxx',
'secret':'xxx',
'action':'AddOrder',
'clientid':client_id,
'domain':domain,
'domaintype':"register",
'billingcycle':"annually",
'regperiod':1,
'noinvoice':True,
'noinvoiceemail':True,
'noemail':True,
'paymentmethod':"stripe",
'domainpriceoverride':0,
'domainrenewoverride':0,
'domainfields':additional_domainfields,
'responsetype':'json'
}
postfields = urlencode(post_data)
c.setopt(c.POSTFIELDS, postfields) # type: ignore
c.perform()
c.reset
I can't find what to use for the array of serialized data, so far all of my tests were for nothing.
I tried any combination of fields on the line:
additional_domainfields = base64.b64encode(phpserialize.dumps({'Entity Type':'INDIVIDUAL', 'EU Country of Citizenship':'IT'})).
Also, tried cheching for the php overrides for field names, so far without success.
Any help would be immensely appreciated
I use dynamic mapping in elasticsearch to load my json file into elasticsearch, like this:
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
def extract():
f = open('tmdb.json')
if f:
return json.loads(f.read())
movieDict = extract()
def index(movieDict={}):
for id, body in movieDict.items():
es.index(index='tmdb', id=id, doc_type='movie', body=body)
index(movieDict)
How can I update mapping for single field? I have field title to which I want to add different analyzer.
title_settings = {"properties" : { "title": {"type" : "text", "analyzer": "english"}}}
es.indices.put_mapping(index='tmdb', body=title_settings)
This fails.
I know that I cannot update already existing index, but what is proper way to reindex mapping generated from json file? My file has a lot of fields, creating mapping/settings manually would be very troublesome.
I am able to specify analyzer for an query, like this:
query = {"query": {
"multi_match": {
"query": userSearch, "analyzer":"english", "fields": ['title^10', 'overview']}}}
How do I specify it for index or field?
I am also able to put analyzer to settings after closing and opening index
analysis = {'settings': {'analysis': {'analyzer': 'english'}}}
es.indices.close(index='tmdb')
es.indices.put_settings(index='tmdb', body=analysis)
es.indices.open(index='tmdb')
Copying exact settings for english analyzers doesn't do 'activate' it for my data.
https://www.elastic.co/guide/en/elasticsearch/reference/7.6/analysis-lang-analyzer.html#english-analyzer
By 'activate' I mean, search is not returned in a form processed by english analyzer ie. there are still stopwords.
Solved it with massive amount of googling....
You cannot change analyzer on already indexed data. This includes opening/closing of index. You can specify new index, create new mapping and load your data (quickest way)
Specifying analyzer for whole index isn't good solution, as 'english' analyzer is specific to 'text' fields. It's better to specify analyzer by field.
If analyzers are specified by field you also need to specify type.
You need to remember that analyzers are used at can be used at/or index and search time. Reference Specifying analyzers
Code:
def create_index(movieDict={}, mapping={}):
es.indices.create(index='test_index', body=mapping)
start = time.time()
for id, body in movieDict.items():
es.index(index='test_index', id=id, doc_type='movie', body=body)
print("--- %s seconds ---" % (time.time() - start))
Now, I've got mapping from dynamic mapping of my json file. I just saved it back to json file for ease of processing (editing). That's because I have over 40 fields to map, doing it by hand would be just tiresome.
mapping = es.indices.get_mapping(index='tmdb')
This is example of how title key should be specified to use english analyzer
'title': {'type': 'text', 'analyzer': 'english','fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}
I'm trying to set data validation rules for my current spreadsheet. One thing that would help me would to be able to view the rules in JSON from data validation rules I have already set (In the spreadsheet UI or within an API call).
Example.
request = {
"requests": [
{
"setDataValidation": {
"range": {
"sheetId": SHEET_ID,
"startRowIndex": 1,
"startColumnIndex": 0,
"endColumnIndex":1
},
"rule": {
"condition": {
"type": "BOOLEAN"},
"inputMessage": "Value MUST BE BOOLEAN",
"strict": "True"
}
}
}
]
}
service.spreadsheets().batchUpdate(spreadsheetId=SPREADSHEET_ID body=request).execute()
But what API calls do I use to see the Data Validation on these range of cells? This is useful for if I set the Data Validation rules in the spreadsheet and I want to see how google interprets them. I'm having a lot of trouble setting complex Datavalidations through the API.
Thank you
To obtain only the "Data Validation" components of a given spreadsheet, you simply request the appropriate field in the call to spreadsheets.get:
service = get_authed_sheets_service_somehow()
params = {
spreadsheetId: 'your ssid',
#range: 'some range',
fields: 'sheets(data/rowData/values/dataValidation,properties(sheetId,title))' }
request = service.spreadsheets().get(**params)
response = request.execute()
# Example print code (not tested :p )
for sheet in response['sheets']:
for range in sheet['data']:
for r, row in enumerate(range['rowData']):
for c, col in enumerate(row['values']):
if 'dataValidation' in col:
# print "Sheet1!R1C1" & associated data validation object.
# Assumes whole grid was requested (add appropriate indices if not).
print(f'\'{sheet["properties"]["title"]}\'!R{r}C{c}', col['dataValidation'])
By specifying fields, includeGridData is not required to obtain data on a per-cell basis from the range you requested. By not supplying a range, we target the entire file. This particular fields specification requests the rowData.values.dataValidation object and the sheetId and title of the properties object, for every sheet in the spreadsheet.
You can use the Google APIs Explorer to interactively determine the appropriate valid "fields" specification, and additionally examine the response:
https://developers.google.com/apis-explorer/#p/sheets/v4/sheets.spreadsheets.get
For more about how "fields" specifiers work, read the documentation: https://developers.google.com/sheets/api/guides/concepts#partial_responses
(For certain write requests, field specifications are not optional so it is in your best interest to determine how to use them effectively.)
I think I found the answer. IncludeGridData=True in your spreadsheet().get
from pprint import pprint
response = service.spreadsheets().get(
spreadsheetId=SPREADSHEETID, fields='*',
ranges='InputWorking!A2:A',includeGridData=True).execute()
You get a monster datastructure back. So to look at the very first data in your range you could do.
pprint(response['sheets'][0]['data'][0]['rowData'][0]['values'][0]['dataValidation'])
{'condition': {'type': 'BOOLEAN'},
'inputMessage': 'Value MUST BE BOOLEAN',
'strict': True}
I am using the python adwords api v201402.
I have an mcc account.
report_downloader = self.client.GetReportDownloader(version='v201402')
# Create report definition.
report = {
'reportName': 'Last 7 days CRITERIA_PERFORMANCE_REPORT',
'dateRangeType': 'LAST_7_DAYS',
'reportType': 'CRITERIA_PERFORMANCE_REPORT',
'downloadFormat': 'CSV',
'selector': {
'fields': ['CampaignId', 'AdGroupId', 'Id', 'CriteriaType',
'Criteria', 'Impressions', 'Clicks', 'Cost']
},
# Enable to get rows with zero impressions.
'includeZeroImpressions': 'false'
}
If I dont add a customer ID I get the below error:
output, return_money_in_micros)
File "/usr/local/lib/python2.7/dist-packages/googleads-1.0.1-py2.7.egg/googleads/adwords.py", line 406, in _DownloadReport
raise self._ExtractError(e)
googleads.errors.AdWordsReportBadRequestError: Type: AuthenticationError.CLIENT_CUSTOMER_ID_INVALID
Trigger: <null>
Field Path: None
How do I add a customer id? I tried adding 'clientCustomerId':"xxx-xxx-xxx" in the hash but I get the below:
File "/usr/local/lib/python2.7/dist-packages/suds_jurko-0.6-py2.7.egg/suds/mx/core.py", line 71, in append
if self.start(content):
File "/usr/local/lib/python2.7/dist-packages/suds_jurko-0.6-py2.7.egg/suds/mx/literal.py", line 86, in start
raise TypeNotFound(content.tag)
suds.TypeNotFound: Type not found: 'clientCustomerId'
This is a bit late, but hopefully this might help others stumbling onto this question.
If you have multiple clients for whom you need to explicitly set the clientCustomerId outside of your yaml, in the instance where you have one MCC but multiple clients, you can do the following:
self.client = AdWordsClient.LoadFromStorage()
self.client.SetClientCustomerId(<client_customer_id>)
After that, you can use the report downloader as needed, and you can re-assign the customer ID as needed.
The clientCustomerId is set within your API client object.
Depending on your goals, you should either set this value in a config file, or in your client method.
Make sure your Googleads.yaml file is configured correctly and in your home directory. I got a similar error and that fixed it.