Original Message:
Sent: Mon April 15, 2024 04:21 PM
From: jack jack
Subject: Maximo REST API not updating on UI and DB even after success response code
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
)
------------------------------
jack jack
Original Message:
Sent: Fri April 12, 2024 06:30 PM
From: Bradley Downing
Subject: Maximo REST API not updating on UI and DB even after success response code
After reading through this I might offer the following: Try to remove one field from the message and try the update again, checking to see if there is some relationship between the two that may be interfering one with the other.
Also the 'extstatus' field implies there is some external system updating this status (perhaps your integration you are building? ;) Is there supposed to be any correlation with the WOSTATUS? Is there an automation script updating the custom attribute from WOSTATUS? Perhaps when you update via API, it invoke a field level automation script and rewrites the attribute to that of the WOSTATUS. Does the date field represent the date of the external system update? Is that also affected by any possible other automation script.
You mention "are currently updated manually using Data Import on a custom Work Order Definitions using a CSV file without any problem." what is the "custom Work Order Definitions" and should you try to invoke that instead of the MXAPIWODETAIL? Perhaps that is the customization I am inferring above, and (since it is not getting passed any values,) it fires with the null values and the code handles nulls, and simply does... nothing? It seems to me this may be a timing issue.
------------------------------
Bradley K. Downing , MBA
Senior Solution Architect
IBM
Bakersfield CA
Original Message:
Sent: Tue April 09, 2024 11:51 PM
From: jack jack
Subject: Maximo REST API not updating on UI and DB even after success 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>"
# `extstatus` and `sdlattdate` are the kays I want to update
update_body = {
"extstatus": "In Progress",
"sdlattdate": "2024-04-09T00: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_dody,
headers=header | {
'x-method-override': 'PATCH',
'x-allow-events': "1",
'x-public-uri': '<BASE-URL>/maximo/oslc',
'patchtype': 'MERGE',
# 'properties': '*',
'properties': 'workorderid,wonum,externalrefid,extstatus,sdlattdate,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 pretty sure that the href value passed corresponds to the document I want to update since I can confirm it after decoding the base64 value which equals <SITE-ID>/<WO-NUM>
Any suggestions and help would be much appreciated, thank you!
------------------------------
jack jack
------------------------------