本文整理汇总了Python中SampleUtilities.pretty_print_request方法的典型用法代码示例。如果您正苦于以下问题:Python SampleUtilities.pretty_print_request方法的具体用法?Python SampleUtilities.pretty_print_request怎么用?Python SampleUtilities.pretty_print_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SampleUtilities
的用法示例。
在下文中一共展示了SampleUtilities.pretty_print_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client and set up some sample data.
client = RestApiClient()
setup_data(client)
# Some endpoints accept path parameters.
# These parameters are inserted into the path portion of the URL at specific
# locations. In this example we are retrieving the contents of a reference
# set named 'rest_api_samples_testset'.
SampleUtilities.pretty_print_request(client, 'referencedata/sets/rest_api_samples_testset', 'GET')
response = client.call_api('referencedata/sets/rest_api_samples_testset', 'GET')
SampleUtilities.pretty_print_response(response)
# Query parameters and path parameters can be combined in a single request.
# Here we are adding a value to the reference set we just looked at.
SampleUtilities.pretty_print_request(client, 'referencedata/sets/rest_api_samples_testset?value=rest_api_sample_value', 'POST')
response = client.call_api('referencedata/sets/rest_api_samples_testset?value=rest_api_sample_value', 'POST')
# Along with GET requests, POST and DELETE requests often return information
# that can be used to confirm the results of the request.
SampleUtilities.pretty_print_response(response)
# Now we can look at the contents of the reference set again to see the
# value we added.
response = client.call_api('referencedata/sets/rest_api_samples_testset', 'GET')
SampleUtilities.pretty_print_response(response)
示例2: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client.
client = RestApiClient()
# Using the /asset_model/properties endpoint with a GET request.
SampleUtilities.pretty_print_request(client, 'asset_model/properties', 'GET')
response = client.call_api('asset_model/properties', 'GET')
# Verify that the call to the API was successful.
if (response.code != 200):
print('Failed to retrieve propertiy list.')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Display the number of properties retrieved.
response_body = json.loads(response.read().decode('utf-8'))
number_of_properties_retrieved = len(response_body)
# Display number of properties, and the names of the properties retrieved.
print(str(number_of_properties_retrieved) + ' properties were retrieved.')
if (number_of_properties_retrieved > 0):
print("Property Names: ", end="")
for property in response_body:
print(str(property['name']) + ', ', end="")
print()
示例3: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client.
client = RestApiClient(version="3.0")
# Using the /asset_model/assets endpoint with a GET request.
SampleUtilities.pretty_print_request(client, "asset_model/assets", "GET")
response = client.call_api("asset_model/assets", "GET")
# Verify that the call to the API was successful.
if response.code != 200:
print("Failed to retrieve asset list.")
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Display the number of assets retrieved.
response_body = json.loads(response.read().decode("utf-8"))
number_of_assets_retrieved = len(response_body)
# Display number of assets, and the IDs of the assets retrieved.
print(str(number_of_assets_retrieved) + " assets were retrieved.")
if number_of_assets_retrieved > 0:
print("Asset IDs: ", end="")
for asset in response_body:
print(str(asset["id"]) + " ", end="")
print()
示例4: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client.
client = RestApiClient()
# Using the /asset_model/assets endpoint with a GET request.
SampleUtilities.pretty_print_request(client, 'asset_model/assets', 'GET')
response = client.call_api('asset_model/assets', 'GET')
# Verify that the call to the API was successful.
if (response.code != 200):
print('Failed to retrieve asset list.')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Display the number of assets retrieved.
response_body = json.loads(response.read().decode('utf-8'))
number_of_assets_retrieved = len(response_body)
# Display number of assets, and the IDs of the assets retrieved.
print(str(number_of_assets_retrieved) + ' assets were retrieved.')
if (number_of_assets_retrieved > 0):
print("Asset IDs: ", end="")
for asset in response_body:
print(str(asset['id']) + ' ', end="")
print()
示例5: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client.
client = RestApiClient()
# While using the REST API an error may occur. Information about
# the error is returned to you in the HTTP response that you receive.
# The HTTP code in the response can tell you a little bit about the error.
# A code in the 400 range indicates that there was a problem with the
# request.
# A code in the 500 range indicates that there was a problem with the
# server.
# In addition to the response code, the response body contains information
# about the error that occurred.
# In this example we are trying to access the contents of a reference data
# set that does not exist.
try:
SampleUtilities.pretty_print_request(client, 'referencedata/sets/rest_api_samples_does_not_exist', 'GET')
response = client.call_api('referencedata/sets/rest_api_samples_does_not_exist', 'GET')
except urllib.error.HTTPError as e:
response = e
SampleUtilities.pretty_print_response(response)
# In this example we are passing a query parameter using the wrong name.
try:
SampleUtilities.pretty_print_request(client, 'referencedata/sets?wrong_name=fake', 'POST')
response = client.call_api('referencedata/sets?wrong_name=fake', 'POST')
except urllib.error.HTTPError as e:
response = e
SampleUtilities.pretty_print_response(response)
示例6: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client and set up some sample data.
client = RestApiClient()
setup_data(client)
# Some endpoints accept body parameters. An example of this is the
# /referencedata/sets/bulkLoad endpoint.
# Body parameters may appear with path parameters, as in this case, but will
# never appear with query parameters.
# You must make sure that you set the content type correctly to a type
# accepted by the endpoint.
headers = client.get_headers().copy()
headers['Content-type'] = 'application/json'
body = b'["abc", "def", "123"]'
# Send the request.
SampleUtilities.pretty_print_request(client, 'referencedata/sets/bulkLoad/rest_api_samples_testset', 'POST', headers=headers)
response = client.call_api('referencedata/sets/bulkLoad/rest_api_samples_testset', 'POST', headers=headers, data=body)
SampleUtilities.pretty_print_response(response)
# The response from the previous command only shows information about the
# set, not the contents of the set. We can view the contents of the set with
# this command:
response = client.call_api('referencedata/sets/rest_api_samples_testset', 'GET')
SampleUtilities.pretty_print_response(response)
示例7: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# For the purpose of this sample, the reading in of credentials, the setup
# of HTTP request headers, and the construction and sending of a request
# object has been abstracted to the 'RestApiClient' class.
# For more information on how these operations are done see the sample
# '01_Authentication.py'.
client = RestApiClient()
# Many API endpoints accept parameters.
# One type of parameter is a query parameter.
# If an endpoint accepts query parameters they are passed after a '?' as
# part of the URL. Each parameter has a name and a value separated by a '='.
# Several parameters can be passed separated by '&' characters.
SampleUtilities.pretty_print_request(client, 'reference_data/sets?name=rest_api_samples_testset&element_type=ALN', 'POST')
response = client.call_api('reference_data/sets?name=rest_api_samples_testset&element_type=ALN', 'POST')
# The response code for successfully creating a set is 201.
if (response.code == 201):
SampleUtilities.pretty_print_response(response)
# The error code that occurs when attempting to create a set that already
# exists is 409.
elif (response.code == 409):
print("Reference set already exists")
response = client.call_api('reference_data/sets/rest_api_samples_testset', 'GET')
SampleUtilities.pretty_print_response(response)
elif (response.code >= 500):
print("An internal server error occurred. You should check your system.")
SampleUtilities.pretty_print_response(response)
else:
print("Some other error has occurred:")
SampleUtilities.pretty_print_response(response)
示例8: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client.
client = RestApiClient(version='3.0')
# Using the /asset_model/properties endpoint with a GET request.
SampleUtilities.pretty_print_request(client, 'asset_model/saved_searches',
'GET')
response = client.call_api('asset_model/saved_searches', 'GET')
# Verify that the call to the API was successful.
if (response.code != 200):
print('Failed to retrieve saved searches list.')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Find the number of saved searches retrieved.
response_body = json.loads(response.read().decode('utf-8'))
number_of_searches_retrieved = len(response_body)
# Display number of searches, and the names of the searches retrieved.
print(str(number_of_searches_retrieved) + ' searches were retrieved.\n')
if (number_of_searches_retrieved > 0):
print("Searching Assets...\n\n")
for search in response_body:
# Retrieve the saved search unique identifier.
saved_search_id = str(search['id'])
saved_search_name = str(search['name'])
print('Running saved search : ' + saved_search_name)
# Using the /asset_model/saved_searches/{saved_search_id}/results
# endpoint with a GET request.
search_endpoint_url = ('asset_model/saved_searches/' +
saved_search_id + '/results')
SampleUtilities.pretty_print_request(client, search_endpoint_url,
'GET')
search_response = client.call_api(search_endpoint_url, 'GET')
if(response.code != 200):
print("Failed to search assets.")
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Find the number of assets found
search_response_body = json.loads(search_response.read().
decode('utf-8'))
number_of_assets_found = len(search_response_body)
# Display the number of assets retrieved.
print(str(number_of_assets_found) + ' assets were retrieved.\n')
print()
示例9: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# First we have to create our client
client = RestApiClient()
# Request the API call only taking a few fields
SampleUtilities.pretty_print_request(client, 'siem/offenses?fields=id,description,' +
'status,offense_type,offense_source', 'GET')
response = client.call_api('siem/offenses?fields=id,description,status,offense_type,offense_source', 'GET')
# Print out the result for the user to see
SampleUtilities.pretty_print_response(response)
# Prompt the user for an ID
offense_ID = input('Select an offense to post a note to. Please type its ID or quit. ')
# Error checking because we want to make sure the user has selected an offense that exists.
while True:
if (offense_ID == 'quit'):
exit(0)
# Make the request to 'GET' the offense chosen by the user
SampleUtilities.pretty_print_request(client, 'siem/offenses/' + str(offense_ID), 'GET')
response = client.call_api('siem/offenses/' + str(offense_ID), 'GET')
# Check response code to see if the offense exists
if (response.code == 200):
break
else:
offense_ID = input('An offense by that ID does not exist. Please try again or type quit. ')
# Print out the offense the user chose
SampleUtilities.pretty_print_response(response)
# Send in the API Call request for the offense's notes
SampleUtilities.pretty_print_request(client, 'siem/offenses/' + str(offense_ID) + '/notes', 'GET')
response = client.call_api('siem/offenses/' + str(offense_ID) + '/notes', 'GET')
# Display all the notes on the offense
SampleUtilities.pretty_print_response(response)
# Confirm that the user wants to make a new note for the offense. We have to check this since it will
# permanently add that note to the offense.
confirmation = input('Would you like to make a new note for offense ' + str(offense_ID) + '? (YES/no)\n')
if (confirmation != 'YES'):
print('You have chosen not to post a new note. Exiting sample.')
exit(0)
# Take in the text for the note. Since the note could be multiple words, and the API calls through a
# url, we are using urllib.parse.quote to preserve the spaces and special characters in the note.
text = urllib.parse.quote(input('Please enter the content of the note.\n'))
# Send in the request for the new note to be put on the offense.
SampleUtilities.pretty_print_request(client, 'siem/offenses/' + offense_ID + '/notes?note_text=' + text, 'POST')
response = client.call_api('siem/offenses/' + offense_ID + '/notes?note_text=' + text, 'POST')
#Display to the user the new note to confirm that it has been created properly.
SampleUtilities.pretty_print_response(response)
示例10: call_api
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def call_api(self, endpoint, method, headers=None, params=[], data=None,
print_request=False):
path = self.parse_path(endpoint, params)
# If the caller specified customer headers merge them with the default
# headers.
actual_headers = self.headers.copy()
if headers is not None:
for header_key in headers:
actual_headers[header_key] = headers[header_key]
# Send the request and receive the response
request = Request(
'https://' + self.server_ip + self.base_uri + path,
headers=actual_headers)
request.get_method = lambda: method
# Print the request if print_request is True.
if print_request:
SampleUtilities.pretty_print_request(self, path, method,
headers=actual_headers)
try:
response = urlopen(request, data)
response_info = response.info()
if 'Deprecated' in response_info:
# This version of the API is Deprecated. Print a warning to
# stderr.
print("WARNING: " + response_info['Deprecated'],
file=sys.stderr)
# returns response object for opening url.
return response
except HTTPError as e:
# an object which contains information similar to a request object
return e
except URLError as e:
if (isinstance(e.reason, ssl.SSLError) and
e.reason.reason == "CERTIFICATE_VERIFY_FAILED"):
print("Certificate verification failed.")
sys.exit(3)
else:
raise e
示例11: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# First we have to create our client
client = RestApiClient(version="3.0")
# This example gives a demonstration of how to create a new closing reason
# for your offenses.
# First, check what closing reasons are already available to avoid
# creating duplicates. Send in the GET request.
SampleUtilities.pretty_print_request(client, "siem/offense_closing_reasons", "GET")
response = client.call_api("siem/offense_closing_reasons", "GET")
# and output the response
SampleUtilities.pretty_print_response(response)
if response.code != 200:
print("Call Failed")
sys.exit(1)
# Double check that the user wants to create a new closing reason
while True:
confirmation = input("Are you sure you want to create a new " + "closing reason? (YES/no) ")
if confirmation == "YES":
break
elif confirmation == "no":
print("Not creating a new closing reason")
exit(0)
else:
print(confirmation + "is not a valid answer.")
# Have the user input the text.
text = input("Please enter the text you want to put in the closing reason.\n")
# Put through the request to add a closing reason with the text the user
# entered as the reason
params = {"reason": text}
response = client.call_api("siem/offense_closing_reasons", "POST", params=params, print_request=True)
SampleUtilities.pretty_print_response(response)
if response.code != 201:
print("Call Failed")
sys.exit(1)
print("Closing reason added")
示例12: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# First we have to create our client
client = RestApiClient()
# This example gives a demonstration of how to create a new closing reason for your
# offenses.
# First, check what closing reasons are already available to avoid creating duplicates
# Send in the GET request
SampleUtilities.pretty_print_request(client, 'siem/offense_closing_reasons', 'GET')
response = client.call_api('siem/offense_closing_reasons', 'GET')
# and output the response
SampleUtilities.pretty_print_response(response)
if (response.code != 200):
print('Call Failed')
sys.exit(1)
# Double check that the user wants to create a new closing reason
while True:
confirmation = input('Are you sure you want to create a new closing reason? (YES/no) ')
if (confirmation == 'YES'):
break
elif (confirmation == 'no'):
print('Not creating a new closing reason')
exit(0)
else:
print(confirmation + 'is not a valid answer.')
# Have the user input the text. quote it to retain special characters like spaces.
text = urllib.parse.quote(input('Please enter the text you want to put in the closing reason.\n'))
# Put through the request to add a closing reason with the text the user entered as the reason
SampleUtilities.pretty_print_request(client, 'siem/offense_closing_reasons?reason=' + text, 'POST')
response = client.call_api('siem/offense_closing_reasons?reason=' + text, 'POST')
SampleUtilities.pretty_print_response(response)
if (response.code != 201):
print('Call Failed')
sys.exit(1)
print('Closing reason added')
示例13: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client and set up some sample data.
client = RestApiClient(version="3.0")
setup_data(client)
# Using the '/sets/{name} endpoint with a GET request we can retrieve the
# contents of our set of suspect addresses.
SampleUtilities.pretty_print_request(client, "reference_data/sets/rest_api_samples_suspect_ips", "GET")
response = client.call_api("reference_data/sets/rest_api_samples_suspect_ips", "GET")
# Based on our business rules, this set should always exist. If it does not
# exist it could be an indication that our security has been breached and
# that an attack is in progress. We should raise an alarm.
if response.code == 404:
print("Something is wrong, a system administrator should investigate.")
sys.exit(1)
# Extract the reference set from the response body.
response_body = json.loads(response.read().decode("utf-8"))
data = response_body["data"]
for element in data:
# For each suspect ip address, pass it to our legacy system to
# validate. If it is a real threat, move it to the blocked list so that
# the configured rules can generate offenses if it is active on our
# network.
ip_address = element["value"]
if legacy_system_logic(ip_address):
SampleUtilities.pretty_print_request(
client, "reference_data/sets/rest_api_samples_blocked_ips?value=" + ip_address, "POST"
)
response = client.call_api("reference_data/sets/rest_api_samples_blocked_ips?value=" + ip_address, "POST")
SampleUtilities.pretty_print_request(
client, "reference_data/sets/rest_api_samples_suspect_ips/" + ip_address, "DELETE"
)
response = client.call_api("reference_data/sets/rest_api_samples_suspect_ips/" + ip_address, "DELETE")
# The result of this processing is that there are some ip addresses now in
# the blocked list.
response = client.call_api("reference_data/sets/rest_api_samples_suspect_ips", "GET")
SampleUtilities.pretty_print_response(response)
# The ip addresses that were not blocked are sill in the suspect list for
# us to watch.
response = client.call_api("reference_data/sets/rest_api_samples_blocked_ips", "GET")
SampleUtilities.pretty_print_response(response)
示例14: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# First we have to create our client
client = RestApiClient()
#----------------------------------------------------------------------------#
#Basic 'GET'
# In this example we'll be using the GET endpoint of siem/offenses without
# any parameters. This will print absolutely everything it can find, every
# parameter of every offense.
# Send in the request
SampleUtilities.pretty_print_request(client, 'siem/offenses', 'GET')
response = client.call_api('siem/offenses', 'GET')
# Check if the success code was returned to ensure the call to the API was
# successful.
if (response.code != 200):
print('Failed to retrieve the list of offenses')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Since the previous call had no parameters and response has a lot of text,
# we'll just print out the number of offenses
response_body = json.loads(response.read().decode('utf-8'))
print('Number of offenses retrived: ' + str(len(response_body)))
#----------------------------------------------------------------------------#
#Using the fields parameter with 'GET'
# If you just print out the result of a call to the siem/offenses GET endpoint
# there will be a lot of fields displayed which you have no interest in.
# Here, the fields parameter will make sure the only the fields you want
# are displayed for each offense.
# Setting a variable for all the fields that are to be displayed
fields = '''id,status,description,offense_type,offense_source,magnitude,\
source_network,destination_networks,assigned_to'''
# Send in the request
SampleUtilities.pretty_print_request(client, 'siem/offenses?fields=' + fields, 'GET')
response = client.call_api('siem/offenses?fields=' + fields, 'GET')
# Once again, check the response code
if (response.code != 200):
print('Failed to retrieve list of offenses')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# This time we will print out the data itself
SampleUtilities.pretty_print_response(response)
#----------------------------------------------------------------------------#
#Using the filter parameter with 'GET'
# Sometimes you'll want to narrow down your search to just a few offenses.
# You can use the filter parameter to carefully select what is returned
# after the call by the value of the fields.
# Here we're only looking for OPEN offenses, as shown by the value of 'status'
# being 'OPEN'
# Send in the request
SampleUtilities.pretty_print_request(client, 'siem/offenses?fields=' + fields +
'&filter=status=OPEN', 'GET')
response = client.call_api('siem/offenses?fields=' + fields + '&filter=status=OPEN', 'GET')
# Always check the response code
if (response.code != 200):
print('Failed to retrieve list of offenses')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# And output the data
SampleUtilities.pretty_print_response(response)
#----------------------------------------------------------------------------#
#Paging the 'GET' data using 'Range'
# If you have a lot of offenses, then you may want to browse through them
# just a few at a time. In that case, you can use the Range header to
# limit the number of offenses shown in a single call.
# In this example only OPEN offenses will be used.
# Call the endpoint so that we can find how many OPEN offenses there are.
response = client.call_api('siem/offenses?filter=status=OPEN', 'GET')
num_of_open_offenses = len(json.loads(response.read().decode('utf-8')))
# Copy the headers into our own variable
range_header = client.get_headers().copy()
# Set the starting point (indexing starts at 0)
page_position = 0
# and choose how many offenses you want to display at a time.
offenses_per_page = 5
# Looping here in order to repeatedly show 5 offenses at a time until we've
# seen all of the OPEN offenses
while True:
#.........这里部分代码省略.........
示例15: main
# 需要导入模块: import SampleUtilities [as 别名]
# 或者: from SampleUtilities import pretty_print_request [as 别名]
def main():
# Create our client and set up some sample data.
client = RestApiClient()
setup_data(client)
# First lets have a look at the data in this reference set
SampleUtilities.pretty_print_request(client, 'reference_data/sets', 'GET')
response = client.call_api('reference_data/sets', 'GET')
SampleUtilities.pretty_print_response(response)
# Suppose we are only interested in the names and the size of each set. We
# can restrict the data we get back with a 'fields' parameter.
fields = 'fields=' + urllib.parse.quote('name,number_of_elements')
SampleUtilities.pretty_print_request(client, 'reference_data/sets?' + fields, 'GET')
response = client.call_api('reference_data/sets?' + fields, 'GET')
SampleUtilities.pretty_print_response(response)
# If this set contained a large amount of data, we might want to process it
# a little bit at a time. To get back only part of the data we can use a
# 'Range' header.
# Note that the range header is indexed form zero, so here we are asking
# for the first 5 items.
range_header = {'Range': 'items=0-4'}
SampleUtilities.pretty_print_request(client, 'reference_data/sets', 'GET', headers=range_header)
response = client.call_api('reference_data/sets', 'GET', headers=range_header)
response_headers = response.info()
SampleUtilities.pretty_print_response(response)
# Note that there is a header in the response that contains information
# about the portion of the data that you requested.
# the 'Content-Range' header tells you which items you got back and how many
# items are in the whole list.
print ('Content-Range header value: ' + response_headers['Content-Range'])
parsed_range_header = response_headers['Content-Range'].split('/')
print('This tells us which items we got back: ' + parsed_range_header[0])
print('This tells us how many items there are in total: ' + parsed_range_header[1])
# We can use this information to get back the data one page at a time
current_position = 5
while(current_position < int(parsed_range_header[1])):
range_string = 'items=' + str(current_position) + '-' + str(current_position + 4)
range_header = {'Range': range_string}
SampleUtilities.pretty_print_request(client, 'reference_data/sets', 'GET', headers=range_header)
response = client.call_api('reference_data/sets', 'GET', headers=range_header)
print((response.info())['Content-Range'])
SampleUtilities.pretty_print_response(response)
current_position = current_position + 5
# Now suppose that we want to find a specific set that contains data we are
# interested in. We can use the filter parameter to do this.
# Some sets were added during the setup of this sample script. Lets find them.
filter_string = 'filter=' + urllib.parse.quote('name between rest_api_samples and rest_api_samplet')
SampleUtilities.pretty_print_request(client, 'reference_data/sets?' + filter_string, 'GET')
response = client.call_api('reference_data/sets?' + filter_string, 'GET')
SampleUtilities.pretty_print_response(response)
# Only some of these sets contain data.
filter_string = 'filter=' + urllib.parse.quote('name between rest_api_samples and rest_api_samplet and number_of_elements>0')
SampleUtilities.pretty_print_request(client, 'reference_data/sets?' + filter_string, 'GET')
response = client.call_api('reference_data/sets?' + filter_string, 'GET')
SampleUtilities.pretty_print_response(response)
response = client.call_api('reference_data/sets?' + filter_string, 'GET')
parsed_response = json.loads(response.read().decode('utf-8'))
for ref_data_set in parsed_response:
print('The sample reference set ' + ref_data_set['name'] + ' contains data')
# the filter parameter supports:
# and, or, and not logical operators as well as brackets to specify
# precedence.
# =, >, <, >=, <=, !=, in, between, is null comparisons.
# Refer to your product documentation for more information about using
# filters.
# You can combine fields, filters, and the range parameter to have precise
# control over the data you get back from the API.
filter_string = 'filter=' + urllib.parse.quote('name between rest_api_samples and rest_api_samplet')
range_header = {'Range': 'items=0-1'}
fields = 'fields=' + urllib.parse.quote('name')
# Here we are asking for only the names of the top two reference sets that
# were added by this sample script.
SampleUtilities.pretty_print_request(client, 'reference_data/sets?' + filter_string + '&' + fields, 'GET', headers=range_header)
response = client.call_api('reference_data/sets?' + filter_string + '&' + fields, 'GET', headers=range_header)
SampleUtilities.pretty_print_response(response)