@@ -76,14 +76,19 @@ def __new__(cls, **kwargs):
7676 if 'company_id' in kwargs :
7777 instance .company_id = kwargs ['company_id' ]
7878
79- if 'minorversion' in kwargs :
80- instance .minorversion = kwargs ['minorversion' ]
81-
82- if instance .minorversion < instance .MINIMUM_MINOR_VERSION :
83- warnings .warn (
84- 'Minor Version no longer supported.'
85- 'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/' ,
86- DeprecationWarning )
79+ # Handle minorversion with default
80+ instance .minorversion = kwargs .get ('minorversion' , instance .MINIMUM_MINOR_VERSION )
81+ if 'minorversion' not in kwargs :
82+ warnings .warn (
83+ 'No minor version specified. Defaulting to minimum supported version (75). '
84+ 'Please specify minorversion explicitly when initializing QuickBooks. '
85+ 'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/' ,
86+ DeprecationWarning )
87+ elif instance .minorversion < instance .MINIMUM_MINOR_VERSION :
88+ warnings .warn (
89+ f'Minor Version { instance .minorversion } is no longer supported. Minimum supported version is { instance .MINIMUM_MINOR_VERSION } . '
90+ 'See: https://blogs.intuit.com/2025/01/21/changes-to-our-accounting-api-that-may-impact-your-application/' ,
91+ DeprecationWarning )
8792
8893 instance .invoice_link = kwargs .get ('invoice_link' , False )
8994
@@ -152,13 +157,12 @@ def change_data_capture(self, entity_string, changed_since):
152157 return result
153158
154159 def make_request (self , request_type , url , request_body = None , content_type = 'application/json' ,
155- params = None , file_path = None , request_id = None ):
160+ params = None , file_path = None , file_bytes = None , request_id = None ):
156161
157162 if not params :
158163 params = {}
159164
160- if self .minorversion :
161- params ['minorversion' ] = self .minorversion
165+ params ['minorversion' ] = self .minorversion
162166
163167 if request_id :
164168 params ['requestid' ] = request_id
@@ -172,7 +176,7 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
172176 'User-Agent' : 'python-quickbooks V3 library'
173177 }
174178
175- if file_path :
179+ if file_path or file_bytes :
176180 url = url .replace ('attachable' , 'upload' )
177181 boundary = '-------------PythonMultipartPost'
178182 headers .update ({
@@ -183,8 +187,11 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
183187 'Connection' : 'close'
184188 })
185189
186- with open (file_path , 'rb' ) as attachment :
187- binary_data = str (base64 .b64encode (attachment .read ()).decode ('ascii' ))
190+ if file_path :
191+ with open (file_path , 'rb' ) as attachment :
192+ binary_data = str (base64 .b64encode (attachment .read ()).decode ('ascii' ))
193+ else :
194+ binary_data = str (base64 .b64encode (file_bytes ).decode ('ascii' ))
188195
189196 content_type = json .loads (request_body )['ContentType' ]
190197
@@ -233,10 +240,16 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
233240 return result
234241
235242 def get (self , * args , ** kwargs ):
236- return self .make_request ("GET" , * args , ** kwargs )
243+ if 'params' not in kwargs :
244+ kwargs ['params' ] = {}
245+
246+ return self .make_request ('GET' , * args , ** kwargs )
237247
238248 def post (self , * args , ** kwargs ):
239- return self .make_request ("POST" , * args , ** kwargs )
249+ if 'params' not in kwargs :
250+ kwargs ['params' ] = {}
251+
252+ return self .make_request ('POST' , * args , ** kwargs )
240253
241254 def process_request (self , request_type , url , headers = "" , params = "" , data = "" ):
242255 if self .session is None :
@@ -248,10 +261,11 @@ def process_request(self, request_type, url, headers="", params="", data=""):
248261 request_type , url , headers = headers , params = params , data = data )
249262
250263 def get_single_object (self , qbbo , pk , params = None ):
251- url = "{0}/company/{1}/{2}/{3}/" .format (self .api_url , self .company_id , qbbo .lower (), pk )
252- result = self .get (url , {}, params = params )
264+ url = "{0}/company/{1}/{2}/{3}" .format (self .api_url , self .company_id , qbbo .lower (), pk )
265+ if params is None :
266+ params = {}
253267
254- return result
268+ return self . get ( url , {}, params = params )
255269
256270 @staticmethod
257271 def handle_exceptions (results ):
@@ -287,11 +301,11 @@ def handle_exceptions(results):
287301 else :
288302 raise exceptions .QuickbooksException (message , code , detail )
289303
290- def create_object (self , qbbo , request_body , _file_path = None , request_id = None , params = None ):
304+ def create_object (self , qbbo , request_body , _file_path = None , _file_bytes = None , request_id = None , params = None ):
291305 self .isvalid_object_name (qbbo )
292306
293307 url = "{0}/company/{1}/{2}" .format (self .api_url , self .company_id , qbbo .lower ())
294- results = self .post (url , request_body , file_path = _file_path , request_id = request_id , params = params )
308+ results = self .post (url , request_body , file_path = _file_path , file_bytes = _file_bytes , request_id = request_id , params = params )
295309
296310 return results
297311
@@ -307,9 +321,12 @@ def isvalid_object_name(self, object_name):
307321
308322 return True
309323
310- def update_object (self , qbbo , request_body , _file_path = None , request_id = None , params = None ):
324+ def update_object (self , qbbo , request_body , _file_path = None , _file_bytes = None , request_id = None , params = None ):
311325 url = "{0}/company/{1}/{2}" .format (self .api_url , self .company_id , qbbo .lower ())
312- result = self .post (url , request_body , file_path = _file_path , request_id = request_id , params = params )
326+ if params is None :
327+ params = {}
328+
329+ result = self .post (url , request_body , file_path = _file_path , file_bytes = _file_bytes , request_id = request_id , params = params )
313330
314331 return result
315332
0 commit comments