Happy Business Starts Here

New Student

Quickstart Guide for Zuora ZOQL requets

I am an intern working at Symantec on the Zuora SOAP API, and I want to interact using ZOQL with python (I'm using suds-jurko with python 3 and requests). Specifically I want to make a test ZOQL query.

 

After reading,

 

https://knowledgecenter.zuora.com/DC_Developers/SOAP_API/M_Zuora_Object_Query_Language

 

It is not clear to me how to make a basic ZOQL call to the ZUORA Soap API. What I have set up is a simple method to login

 

from suds.client import Client
from suds.plugin import MessagePlugin

url = "https://apisandbox.zuora.com/apps/services/a/75.0"



USERNAME ="REDACTEDUSERNAME" 

PASSWORD = "REDACTEDPASSWORD"


wsdl_url ="PATH\\TO\\WSDL\\CONTIANING\\zuora.a.75.0.wsdl"
jar = "file:\\\\"+wsdl_url
myclient = Client(jar,plugins=[UnicodeFilter()])
print(myclient.service.login(USERNAME,PASSWORD))

And from printing the client, I can see a session token. So now I'm trying to figure out how to send a ZOQL query. What I did on the next line was:

 

print(myclient.service.zquery('SELECT Id, Name from Account Where ID =\'4028e69926e9852f0126ead18246043f\''))

But it doesn't appear that there is a service.zquery() method, and the documentations doesn't give a quickstart guide, or code-example, (it just covers the sql statements) so i'm not sure how to proceed. 

 

 

4 REPLIES 4
Support SME

Re: Quickstart Guide for Zuora ZOQL requets

Hi @sidatsymantec,

 

While I can't help you with anything specific to Python, I'd like to guide you to the following articles on Exports that might be helpful, especially the first one:

 

https://knowledgecenter.zuora.com/DC_Developers/SOAP_API/E1_SOAP_API_Object_Reference/Export/Create_...

 

https://knowledgecenter.zuora.com/DC_Developers/SOAP_API/E1_SOAP_API_Object_Reference/Export

 

https://knowledgecenter.zuora.com/DC_Developers/SOAP_API/M_Zuora_Object_Query_Language/Export_ZOQL/B...

 

https://knowledgecenter.zuora.com/DC_Developers/SOAP_API/M_Zuora_Object_Query_Language/Export_ZOQL/A...

 

https://knowledgecenter.zuora.com/DC_Developers/SOAP_API/M_Zuora_Object_Query_Language/Export_ZOQL

 

Could you provide some additional details on what are you trying to export / query exactly, and for what purpose? I just want to make sure ZOQL is the best practice for your needs, or if you could go with a simple query() call.



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

New Student

Re: Quickstart Guide for Zuora ZOQL requets

I want to be able to scan over the entire collection of company subscriptions for email matches

 

For example

 

"select (param1) (param2) ... where accountEmail = "SomeFixed@EmailAddress" " 

 

Our objective is to be able to to, given a data base of emails, generate another database of (databases of ( accounts or subscriptions or etc... ))

Guru

Re: Quickstart Guide for Zuora ZOQL requets

@sidatsymantec So you have a good start but a few things to fix:

 

1. There is no soap method "zquery". Per the WSDL the method is "query" which you can also inspect by doing:

print(myclient)

Service ( ZuoraService ) tns="http://api.zuora.com/"
   Prefixes (3)
      ns0 = "http://api.zuora.com/"
      ns1 = "http://fault.api.zuora.com/"
      ns2 = "http://object.api.zuora.com/"
   Ports (1):
      (Soap)
         Methods (14):
            amend(AmendRequest[] requests)
            billingPreview(BillingPreviewRequest[] requests)
            calculateChargeMetrics(calculateRequest[] request)
            create(ns2:zObject[] zObjects)
            delete(xs:string type, ID[] ids)
            execute(xs:string type, xs:boolean synchronous, ID[] ids)
            generate(ns2:zObject[] zObjects)
            getUserInfo()
            login(xs:string username, xs:string password)
            query(xs:string queryString)
            queryMore(QueryLocator queryLocator)
            rasd()
            subscribe(SubscribeRequest[] subscribes)
            update(ns2:zObject[] zObjects)
         Types (84):
            ns2:Account
            ns2:AccountingCode
           [Truncated]

2. Once you do that, you will still need to inject the header for the session id returned to you from the login call. Disclaimer: I just played with this Python library for 15 minutes and therefore this is not likely the best way to inject this, but it worked in my quick and dirty test:

 

[Your initial block of initializing code]

result = myclient.service.login(USERNAME,PASSWORD)

print(result.Session)

ns = ('zns', 'http://api.zuora.com/')
sh = Element('SessionHeader', ns=ns)
sh.append(Element('session', ns=ns).setText(result.Session))
myclient.set_options(soapheaders=sh)

print(myclient.service.query("SELECT Id, Name FROM Account WHERE Id = '1234567890'"))

After that I could call any query i wanted to pull info from the API.

 

A few additional tips to consider when dealing with the SOAP API:

 

1. There are no JOINS so you need to join manually or by sequential queries. Sometimes there is a REST API that will handle a particular use case more efficiently. So choose the best API for the job.

 

2. If you do need to chain SOAP calls together, remember that your SOAP call can contain up to 200 where clauses, so you can batch your synthetic JOINS into groups of 200 to call the API. 

 

For example: Lets say you wish to get all the account details that have a Subscription that began after January 1, 2016. You would first query Subscriptions:

SELECT Id, AccountId FROM Subscription WHERE ContractEffectiveDate > "2016-01-01'

Now this will return you a list of subscription id and their associated account id. For the sake of example, lets say there were 300 of them.

Now you need to batch your calls to query the account details... So you construct the following:

SELECT Id, Account, Balance FROM Account WHERE Id = {First ID} OR Id = {Second ID} ..... Up to 200 WHERE clauses

You would repeat the query with the remaining 100 account ids

 

So all told you have 3 queries to complete this. In our systems I have a wrapper that I can pass an array of ID's to and it handles the batching and rate limiting appropriately for bulk queries like this.

 

3. As with the query batch limit, there is a result batch limit (max of 2000) but can also be adjusted by SOAP headers. If your results excede the limit, you will need to continue the query using queryMore() with the query locator

 

4. If you need bulk collections of data, sometimes using the async export API is better as it will handle many of the complex JOINS for you on the backend and return you a CSV result set you can parse in your application.

 

Hope this helps you get going with the API.

Master

Re: Quickstart Guide for Zuora ZOQL requets

I am also a newbie, and I was never able to make a python script based on suds module work with Zuora. Eventually I *did* get a newer SOAP module named Zeep to work. 

 

See sample code at http://community.zuora.com/t5/API/Python-quickstart/m-p/10779/highlight/true#M403