From service to JSON

654 views
Skip to first unread message

Osso romain

unread,
Oct 24, 2018, 7:01:57 AM10/24/18
to AdWords API and Google Ads API Forum
Hey, i'm using the adword api for a while but only for a reporting purpose.
 
Presently to extract the "structure" of my ads, adgroups, campaigns etc. I'm using the python SDK.
 
My question is how could I save the datas I get from a service as " AdGroupAdService " in JSON ? 

Is there a function in the sdk ? I cannot find anything on the documentation
 
Thanks for help.

Milind Sankeshware (AdWords API Team)

unread,
Oct 24, 2018, 1:54:36 PM10/24/18
to AdWords API and Google Ads API Forum
Hi Osso,

I am afraid that you will get the data in XML format only. However, you could convert the response in XML to JSON at your end. Please find the sample examples from the stack overflow, which might be helpful for you. Let me know if you have any further questions. 

Thanks,
Milind, AdWords API Team

Osso romain

unread,
Oct 25, 2018, 3:49:33 AM10/25/18
to AdWords API and Google Ads API Forum
Hi 

When i'm getting the datas from a service :

datas = adwords_client.GetService('AdGroupAdService', 'v201809').get(selector)
datas
= datas['entries']

print(str(datas))

it will pint something like this :

[{
   
'id': 1xxxxxx,
   
'campaignGroupId': None,
   
'name': '1xxxxxe',
   
'status': 'PAUSED',
   
'servingStatus': 'SERVING',
   
'startDate': 'xxxxxx',
   
'endDate': 'xxxxx0',
   
'budget': {
       
'budgetId': xxxxxx,
       
'name': 'Budget Marque',
       
'amount': {
           
'ComparableValue.Type': 'Money',
           
'microAmount': 80000000
       
},
       
'deliveryMethod': 'STANDARD',
       
'referenceCount': 17,
       
'isExplicitlyShared': True,
       
'status': 'ENABLED'
   
},

Which is not json formator xml format.

So let's print the type of "datas". 
It is a list of "zeep.objects.Campaign". I think it's a class of campaigns. But how do i do to get it in XML or either json ? 

There are no informations about that on the sdk .


Thanks for your help,

Regards 

Dorian Kind

unread,
Oct 25, 2018, 7:29:33 AM10/25/18
to AdWords API and Google Ads API Forum
Hi Osso,

you can use the `zeep.helpers.serialize_object` helper to convert a SOAP object as returned by zeep into a native dict and then turn that into JSON via `json.dumps`.

Cheers,
Dorian
Reply all
Reply to author
Forward
0 new messages