Error occurs while updating a user via Portal API using PUT on Users resource

Document ID : KB000102353
Last Modified Date : 18/06/2018
Show Technical Document Details
Introduction:
Question:
User needs to update an API Portal (SaaS) User via PAPI.
In details they want to change its role from OrgAdmin (RoleId: 00000005-0005-0005-0005-000000000005) to Developer (RoleId: 00000006-0006-0006-0006-000000000006).
They followed both the instructions stated in the documentation https://docops.ca.com/ca-api-management-saas/en/publishers/portal-api-papi#!/Users/updateUser (PUT on /Users resource) and also the info found in the PAPI page (https://apim-apim-XXX-prod.dev.ca.com/admin/app/api-explorer). Anyway we obtain an error while updating the user; here the details about the PUT request and the error obtained.

Request: 
- Endpoint: https://apim-ssg-apim-XXX-prod.app.prod.XXX.dev.ca.com/XXX/Users('18a7348f-e30f-4f9b-a0c3-36acf93ff489') 
- Payload: 

"Uuid": "18a7348f-e30f-4f9b-a0c3-36acf93ff489", 
"FirstName": "Daniele", 
"LastName": "Tonna", 
"Username": "DanieleTonnaTest", 
"Email": "userXXX@hotmail.com", 
"RoleUuid": "00000006-0006-0006-0006-000000000006", 
"OrganizationUuid": "0297a922-8f21-4932-b7f9-60564c6ed7f6", 
"NotifyUser": true, 
"Locale": "en", 
"Status": "ENABLED" 


Response: 
- HTTP Status: 500 
- Payload: 

"error" : { 
"code" : "ServerErrorException", "message" : { 
"lang" : "en-US", "value" : "Internal Server Error" 




 
Environment:
Portal 4.2.7.1 (SaaS)
Answer:
User is basically trying to update the last orgAdmin of the organisation to a developer of the same organisation.
This is not allowed and hence the papi apis fail with a http status code 500. 

However the development is working on changing the http status code from 500 to 4XX, and a more intuitive response message. 

* In addition, while updating a orgAdmin or a developer, the field "RoleName": "devorgadministrators" or "RoleName": "developers" respectively is a mandatory field and should be present in the body of the request.
 
* If the request body does not have the above "RoleName" field. Hence the request fails every time with a 500 (Internal Server Error. Certain fields are missing from the request.).
 
* Had the user provided the field "RoleName": "devorgadministrators" in the payload, he would have got the exact error, which would have been
  400 (Unable to change the role of the last orgadmin in an organization to a developer user).

* However, since the Model Schema, present on the page, does not mention about the ‘”RoleName” : “String”’ field, the user would have
   ignored the field.
 
* Conveying this information to the user is necessary as, updating other fields (other than role) of a developer or a OrgAdmin user would also fail, if he does not provide the ‘”RoleName” : “String”’  field.