Happy Business Starts Here

How to get last month data in ZOQL

Valued Scholar

How to get last month data in ZOQL

Hello All,

 

I'm using Python to connect to zuora and get data . 1st of every month , I need to get data for the last month . I want to automate my script so that if I ran this any time it should go to last month and filter for that month only.


I have this script in python to get last month first and last day.

 

import time
import datetime
now = time.localtime()
last = datetime.date(now.tm_year, now.tm_mon, 1) - datetime.timedelta(1)
first = last.replace(day=1)

 

Now I want to pass values from first and last variables to ZOQL ..as shown below ..but it's not working , any suggestions or any other better alternate ways to get last month data only .

 

create_export_Invoice_Item = "{\n \"Format\": \"csv\", \n \"Name\": \"Z_II\", \n \"Query\": \"select * from InvoiceItem where Invoice.InvoiceDate >= 'first' and Invoice.InvoiceDate <= 'last' and Invoice.Status = 'Posted'\", \n \"Status\": \"Processing\", \n \"Zip\": false\n}"

 

Today I'm passing values like this by changing every month before I run my python script

 

create_export_Invoice_Item = "{\n \"Format\": \"csv\", \n \"Name\": \"Z_II\", \n \"Query\": \"select * from InvoiceItem where Invoice.InvoiceDate >= '2018-12-01' and Invoice.InvoiceDate <= '2018-12-31' and Invoice.Status = 'Posted'\", \n \"Status\": \"Processing\", \n \"Zip\": false\n}"

 

Thanks

2 REPLIES
Community Manager

Re: How to get last month data in ZOQL

Hi @myzuora!

 

@bolaurent has done a lot with Zuora and Python. Have you checked out some of her posts in the Community (see list here)?


Lana Lee | Senior Community Manager and Strategist
"To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.” - Ralph Waldo Emerson
Valued Scholar

Re: How to get last month data in ZOQL

Thanks .I don't find the required answer in those posts..