Thank you, Martha! I will let you know how it goes.
Original Message:
Sent: 06-22-2022 08:58
From: Martha Fiske
Subject: REST to update user data
Hi Lynne,
I had some trouble using the py_jama_rest_client so I used import requests.
I was able to update items with the following code:
Note - it was recommended in an article I read to lock the item while making the update.
import requests
#get existing item
lock_url = url+'rest/v1/items/'+str(data['jama_id'])+'/lock'
response = requests.put(lock_url,json={"locked":True},auth=(username, secret),headers=headers)
#get item
item_url = url+'rest/v1/items/'+str(data['jama_id'])
item_response = requests.get(item_url,auth=(username, secret),headers=headers)
item = item_response.json()
#update fields
item['data']['fields'][<field to update>] = data[<new value>].
response = requests.put(item_url,json=item['data'],auth=(username, secret),headers=headers)
# unlock item
response = requests.put(lock_url,json={"locked":False},auth=(username, secret),headers=headers)
#print(response)
Hope this helps.
------------------------------
Martha Fiske
Lucid Motors
Original Message:
Sent: 06-20-2022 15:42
From: lynne banki
Subject: REST to update user data
I am currently using py_jama_rest_client.client
for api calls against my running instance. Using users = client.get_users()
I am able to successfully get my user records. After targeting a specific record to be updated: {'id': 105, 'username': 'devtest@fakecompany.com', 'firstName': 'Dev', 'lastName': 'Test', 'email': 'devtest@fakecompany.com', 'phone': '', 'title': '', 'location': '', 'licenseType': 'FLOATING', 'active': True, 'authenticationType': {'id': 2, 'name': 'IdP'}, 'type': 'users'}
I would like to use client.put_user()
to update the edited username field. Following Jama's definition: put_user ( self, user_id, username, password, first_name, last_name, email, phone=None, title=None, location=None)
However, this generates an API response error:
You must specify an authentication type when the authentication mode is Basic+IdP
Only the prescribed parameters in the above definition are accepted. But the shape of our user data is different.
As far as I can tell, API IDs are different than UserIds, so the ability to patch
based on the API ID is not an option.
Questions:
- If not
py_jama_rest_client
, what can be used programmatically to update username/email? I can do this through the interactive Jama REST API, but would like to create an app for bulk changes. - Can user data (username, email) be
PUT
with requests
(Python) or fetch
(JavaScript)? Are there examples including oauth?
------------------------------
lynne banki
Blue Origin
Kent WA
------------------------------