|
|
@ -99,7 +99,7 @@ def validaterestapi(baseurl, reqval, reqtype, data={}): |
|
|
# 20Feb2022 Support patch |
|
|
# 20Feb2022 Support patch |
|
|
# 28Feb2022 Added functionality to optionally pass in etags, and to request they be returned, for API endpoints that use them |
|
|
# 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 |
|
|
# 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 |
|
|
# response error if status code between these numbers |
|
|
if (400 <= ret.status_code <=599): |
|
|
if (400 <= ret.status_code <=599): |
|
|
|
|
|
if returnResponse: |
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
print("http response code: "+ str(ret.status_code)) |
|
|
else: |
|
|
print("ret.text: "+ret.text) |
|
|
print("http response code: "+ str(ret.status_code)) |
|
|
result=None |
|
|
print("ret.text: "+ret.text) |
|
|
if stoponerror: sys.exit() |
|
|
result=None |
|
|
|
|
|
if stoponerror: sys.exit() |
|
|
|
|
|
|
|
|
# return the result |
|
|
# return the result |
|
|
else: |
|
|
else: |
|
|
@ -170,9 +173,14 @@ def callrestapi(reqval, reqtype, acceptType='application/json', contentType='app |
|
|
if 'etag' in ret.headers: |
|
|
if 'etag' in ret.headers: |
|
|
etagOut=ret.headers['etag'] |
|
|
etagOut=ret.headers['etag'] |
|
|
|
|
|
|
|
|
# ONLY if the caller specifically asked for an etag to be returned, return one |
|
|
if returnResponse: |
|
|
if returnEtag: |
|
|
# 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; |
|
|
return result,etagOut; |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
# Otherwise, return only the result as normal. |
|
|
# Otherwise, return only the result as normal. |
|
|
# This avoids breaking anything that does not expect an etag to be returned |
|
|
# This avoids breaking anything that does not expect an etag to be returned |
|
|
|