I have finally figured out what the problem was.
It was a problem with my Python code, where I have to pass the fields to be updated as json payload instead of as a raw dictionary body or as the POST request parameters. Also `lean` has to be passed as a URL parameter.
For anyone struggling with a similar issue, here is what the complete Python code looks like:
import requests
API_KEY = ""
URL = r""
workorderid = r"" # Must be a `href` value from `GET` request. View Jason's comment for more info
update_req_headers = {
'accept': 'application/json',
'x-method-override': 'PATCH',
'x-allow-events': '',
'patchtype': 'MERGE',
'apikey': API_KEY,
'Content-Type': 'application/json',
'properties': 'workorderid,wonum,externalrefid,extstatus,sdlattdate,siteid,orgid',
}
payload = {
"extstatus": "In Progress",
"sdlattdate": "2024-04-15T00:00:00+12:00"
}
resp = requests.post(
url=f"{URL}/{workorderid}?lean=1",
headers=update_req_headers,
# data=payload
json=payload
)
------------------------------
Harsh Kumaresan
Tuatahi First FIbre
------------------------------
Original Message:
Sent: 04-10-2024 22:05
From: Harsh Kumaresan
Subject: Maximo REST API not performing write operations to DB in spite of 200 response code
I am trying to update custom keys in workorder table (WO) via Maximo REST API. Specifically, I am making use of the /maximo/oslc/os/mxapiwodetail API endpoint to retrieve details using GET request and update using POST request.
Below is the Python code which I use to achieve the same.
import requests
API_KEY = "<MY-API-KEY>"
LOGIN_URL = r"https://<BASE-URL>/maximo/oslc/os/mxapiwodetail"
header = {
"apikey": API_KEY,
}
workorderid = "<href-base64-value>" # Example: _VUZBL1dPMTAwMDAwNA--
# `extstatus` and `sdlattdate` are the kays I want to update
update_body = {
"extstatus": "In Progress",
"sdlattdate": "2024-04-11T00:00:00+12:00",
"wonum": "<WO-NUM>",
"externalrefid": "<ext-id>",
"siteid": "<SITE-ID>",
"orgid": "<ORG-ID>",
}
resp = requests.post(
url=f"{LOGIN_URL}/{workorderid}",
params=update_body,
headers=header | {
'x-method-override': 'PATCH',
'x-allow-events': "1",
'x-public-uri': '<BASE-URL>/maximo/oslc',
'patchtype': 'MERGE',
'properties': 'workorderid,wonum,externalrefid,uffextstatus,uffsdlattdate,siteid,orgid',
}
)
print(f"{resp.json()=}")
The above request returns a 200 status code, however, the data is not updated both on the response JSON via properties option as well as on the Maximo UI.
I am confident that the API call is made on the correct endpoint for this task as per the RESTful API swagger documentation page and I can see the keys from the API response via the `properties` header option, with the value being the older one and not the supposed to be updated one.
I am also pretty sure that the base64 value passed via `workorderid` variable corresponds to the document I want to update since I can confirm it after decoding the base64 value which equals <SITE-ID>/<WO-NUM> for the document I am trying to update.
Any help or suggestions in resolving this issue is much appreciated.
Thanks in advance :)
#Administration
#Architecture
#Assets
#EverythingMaximo
#Integrations
#MaximoApplicationSuite
#MaximoUserGroups
#WorkCenters
#WorkManagement
------------------------------
Harsh Kumaresan
------------------------------