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



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

    Posted Thu April 11, 2024 10:02 PM

    Thank you for your suggestion Juris.

    I tried this and it did not work.



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



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

    Posted Thu April 11, 2024 07:46 AM

    Since you are able to fetch the values, that means the attributes are not excluded (if persistent) or they were included (if non-persistent) which makes it a bit more complicated. It is possible that these values are set as restricted on the object structure which would indicate to the framework that you did not want the framework to take the values directly and put on the object. Open the object structure in the Object Structures application and use the Inbound Setting Restrictions action. See if these attributes show as restricted.

    In my screenshot below for example, the FIRSTAPPRSTATUS is restricted so the MIF framework will not automatically set the value if it's provided in a message. The assumption is that this attribute is either never intended to be set through the MIF or that the inbound processing class will handle how to process it appropriately like the STATUS attribute. 

    Beyond that, since these are custom attributes you'd have to look to see if there is any logic on those fields that would cause it to revert. 



    ------------------------------
    Steven Shull
    ------------------------------



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

    Posted Thu April 11, 2024 10:25 PM

    Thanks for your suggestions Steven.

    I checked the WorkOrder Object Structure and it is not restricted

    I would also like to point out that the keys I am trying to update via REST API are currently updated manually using Data Import on a custom Work Order Definitions using a CSV file without any problem. This custom Work Order Definitions is created based on the default Work Order Definitions and both of the consists of the custom keys I want to update, and the fields are not restricted.



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



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

    Posted Thu April 11, 2024 05:00 PM

    Hi Jack

    Did you get this working?

    Is it possibly because you are initialising update_body but are  passing in update_dody?

    Regards

    Paul



    ------------------------------
    Paul Adlington
    ------------------------------



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

    Posted Thu April 11, 2024 10:05 PM

    Hi Paul,

    I made a typo while masking the script before posting here. My apologies.



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



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

    Posted Fri April 12, 2024 06:30 PM

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



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

    Posted Mon April 15, 2024 04:21 PM

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



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

    Posted Mon April 15, 2024 11:52 PM

    Congratulations!



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