diff --git a/sharedfunctions.py b/sharedfunctions.py index 8c2e887..68ca6ba 100755 --- a/sharedfunctions.py +++ b/sharedfunctions.py @@ -99,7 +99,7 @@ def validaterestapi(baseurl, reqval, reqtype, data={}): # 20Feb2022 Support patch # 28Feb2022 Added functionality to optionally pass in etags, and to request they be returned, for API endpoints that use them -def callrestapi(reqval, reqtype, acceptType='application/json', contentType='application/json',data={},header={},stoponerror=1,returnEtag=False,etagIn=''): +def callrestapi(reqval, reqtype, acceptType='application/json', contentType='application/json',data={},header={},stoponerror=1,returnEtag=False,etagIn='',returnResponse=False): # get the url from the default profile @@ -146,11 +146,14 @@ def callrestapi(reqval, reqtype, acceptType='application/json', contentType='app # response error if status code between these numbers if (400 <= ret.status_code <=599): + if returnResponse: + return ret - print("http response code: "+ str(ret.status_code)) - print("ret.text: "+ret.text) - result=None - if stoponerror: sys.exit() + else: + print("http response code: "+ str(ret.status_code)) + print("ret.text: "+ret.text) + result=None + if stoponerror: sys.exit() # return the result else: @@ -170,9 +173,14 @@ def callrestapi(reqval, reqtype, acceptType='application/json', contentType='app if 'etag' in ret.headers: etagOut=ret.headers['etag'] - # ONLY if the caller specifically asked for an etag to be returned, return one - if returnEtag: + if returnResponse: + # ONLY if the caller specifically asked for the whole resposne object, return it + return ret + + elif returnEtag: + # ONLY if the caller specifically asked for an etag to be returned, return one return result,etagOut; + else: # Otherwise, return only the result as normal. # This avoids breaking anything that does not expect an etag to be returned