REST API - HTTP PATCH Method
4 min
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" } ] } ] xml data in the request body must adhere to the blueprint rest api xml schema 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 rest api update artifacts request docid ifyqewn9aefvmmfdsnvt 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