REST API - HTTP PATCH Method
The HTTP PATCH method allows you to update information based on data that you include in the body of the request.
For example, here is a list of artifacts included in the request body (in JSON format):
[
{
"Id": 220914,
"Properties": [
{
"PropertyTypeId": 9988,
"TextOrChoiceValue": "Traveler Booking 1"
}
]
}
]
Why should I do if I cannot use the PATCH method?
In some environments, the firewall may not support the PATCH method, or the PATCH method may be disabled. It is possible to use HTTP POST method instead of HTTP PATCH.
To submit information using the HTTP POST method instead of HTTP PATCH, you must add the following information to the request header to override the PATCH method:
X-HTTP-Method-Override: PATCH
Python Example
Below is a python example that submits an Update Artifacts request using the PATCH method.
def update_artifacts():
# obtain a token from our get_token() function
token = get_token()
# Of course, this ID would generally come from somewhere else instead of hardcoding it.
project_id = "220870"
# build the resource uri for listing artifacts in a given project
resource_uri = 'https://production.blueprintcloud.com/api/v1/projects/' + project_id + '/artifacts/'
# specify header parameters
request_header={
'Authorization' : 'BlueprintToken ' + token,
'Accept' : 'application/json',
'Content-Type' : 'text/json'
}
# specify the uri parameters
uri_parameters_list={
}
# create the request uri with the uri parameters
request_uri = resource_uri + '?' + urllib.parse.urlencode(uri_parameters_list)
output_requesturi(request_uri)
# the request body would generally built from external data instead of hardcoding it
# for demonstration purposes, an example is provided in both xml and json format
artifactid_to_update = "220914"
propertyid_to_update = "9988"
new_property_value = "Traveler Booking 1"
xml_request_body = ('''
<Artifacts xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.blueprintsys.com/blueprint/api/v1">
<Artifact>
<Id>%s</Id>
<Properties>
<Property>
<PropertyTypeId>%s</PropertyTypeId>
<TextOrChoiceValue>%s</TextOrChoiceValue>
</Property>
</Properties>
</Artifact>
</Artifacts>
''')% (artifactid_to_update, propertyid_to_update, new_property_value)
json_request_body = ('''
[
{
"Id": %s,
"Properties": [
{
"PropertyTypeId": %s,
"TextOrChoiceValue": "%s"
}
]
}
]
''')% (artifactid_to_update, propertyid_to_update, new_property_value)
# set the request body to the proper format for Content-Type:text/json
request_body=json_request_body
output_requestbody(request_body)
# submit the request using HTTP PATCH method
response = requests.patch(request_uri, request_body, headers=request_header)
return response