Maximo

 View Only
Expand all | Collapse all

Maximo REST API not updating on UI and DB even after success response code

  • 1.  Maximo REST API not updating on UI and DB even after success response code

    Posted Wed April 10, 2024 09:37 AM

    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
    ------------------------------


  • 2.  RE: Maximo REST API not updating on UI and DB even after success response code

    IBM Champion
    Posted Wed April 10, 2024 10:27 AM

    Jack,

     

    You need to first find the record id for the record you want to update which will have a url something like <BASE-URL>/maximo/oslc/os/mxapiwodetail/_QkVERk9SRC8xMTQ4 . I have a post here explaining how those resource ids are constructed, https://www.sharptree.io/blog/2023/2023-06-20-resource-ids/ but you should see it as the href attribute in the query response.

     

    From there you do POST method as you have in your example.  Note that you don't need to include that attributes you don't want to update since they are already in the resource Id.

     

    Regards,

    Jason






  • 3.  RE: Maximo REST API not updating on UI and DB even after success response code

    Posted Wed April 10, 2024 09:52 PM

    Thanks for your response Jason,

    The `workorderid` variable is assigned a record id which looks something like this:

    _VUZBL1dPMTAwMDAwNA--

    The above value is extracted from the `href` of a `GET` API call performed to the same API endpoint.

    When I try to do a `POST` API call with the code I provided, I am able to retrieve fields from the response using the `properties` option for the same document I am attempting to update on, but the value remains the same and is not getting updated.



    ------------------------------
    jack jack
    ------------------------------



  • 4.  RE: Maximo REST API not updating on UI and DB even after success response code

    Posted Thu April 11, 2024 01:24 AM

    Hello!

    When changing status we are using something like this (in url format, of course with POST method)

    https://url/maximo/rest/os/mxwo/127683?lean=1&siteid=SOMESITE&status=APPR&mxlaction=Change&apikey=someAPIkey



    ------------------------------
    Juris Flugins
    ------------------------------