---
title: How to update a Selection field definition via the RESTful API
slug: user-guide-10x/how-to-update-a-selection-field-definition-via-the-restful-api
docTags: 
createdAt: 2025-12-15T08:09:07.074Z
---

When altering a Swimlane application via the RESTful, use the PUT /app/id endpoint. A common pitfall, when creating/altering Selection fields within an app via code, is that the burden is on the client code to make sure that every value defined for a Selection field must have a unique identifier. The Swimlane user guide doesn’t specify that such identifiers must be generated, and it does not give guidance on their proper form.

The code for generating the identifier can be found here. This code will be included in the following sample illustrating how to fetch an existing application definition and alter an existing Selection field. The field's original values are “red”, “yellow”, and “blue”. The snippet below removes the value “blue” and adds two others, “green” and “orange”:

:::BlockQuote
from swimlane import Swimlane
import json
import copy
import time
import binascii
import os

&#x20;
def random\_objectid():
&#x20; """Returns a randomly generated MongoDB ObjectId."""
&#x20; timestamp = '\{0\:x}'.format(int(time.time()))
&#x20; rest = binascii.b2a\_hex(os.urandom(8)).decode('ascii')
&#x20; return timestamp + rest


\# Fetch the application's definition via the Swimlane Driver:

swimlane = Swimlane('https\://HOSTNAME', 'USER', 'PASSWORD', verify\_ssl=False)
app = swimlane.apps.get(name='APP-NAME')

\# Fetch the Selection field's definition and print its values, "red", "yellow", and "blue":

selection\_field\_def = app.get\_field\_definition\_by\_name('Selection')
\#print(json.dumps(selection\_field\_def, sort\_keys=True, indent=4, separators=(",", ": ")))


\# Find and remove "blue", and print to confirm success:

for field\_def in app.\_raw\['fields']:
&#x9;if field\_def\['id'] == selection\_field\_def\['id']:
&#x9;	count = 0
&#x9;	for val in field\_def\['values']:
&#x9;		if val\['name'] == 'blue':
&#x9;			del field\_def\['values']\[count]
&#x9;			break
&#x9;		count += 1
print('Blue has been removed\n\n')
print(json.dumps(app.\_raw\['fields'], sort\_keys=True, indent=4, separators=(",", ": ")))

\# Add two new values, and print to confirm success:

for field\_def in app.\_raw\['fields']:
&#x9;if field\_def\['id'] == selection\_field\_def\['id']:
&#x9;	\# Copy the structure of an existing value:
&#x9;	new\_val\_green = copy.deepcopy(field\_def\['values']\[0])
&#x9;	new\_val\_green\['name'] = 'green'
&#x9;	new\_val\_green\['id'] = random\_objectid()
&#x9;	new\_val\_orange = copy.deepcopy(field\_def\['values']\[0])
&#x9;	new\_val\_orange\['name'] = 'orange'
&#x9;	new\_val\_orange\['id'] = random\_objectid()
&#x9;	field\_def\['values'].append(new\_val\_green)
&#x9;	field\_def\['values'].append(new\_val\_orange)
&#x9;	break
print('Orange and Green have been added\n\n')
print(json.dumps(app.\_raw\['fields'], sort\_keys=True, indent=4, separators=(",", ": ")))

\# Finally, persist the field's alteration to the Swimlane server, and print to confirm success:

resp = swimlane.request(
&#x20;   'PUT',
&#x20;   '/app/\{0}'.format(app.id),
&#x20;   json=app.\_raw
)
print str(resp.status\_code)
\#print resp.text
:::


Please note that when Selection field definitions are altered, via the Swimlane UI’s app-build page or via client code, as shown above, problems can ensue that make it difficult to retrieve affected records via the Swimlane Driver.
