Maximo Open Forum

 View Only
  • 1.  Post linked document to MAS

    Posted 5 days ago

    Perhaps someone has a working example of posting a linked doc via a rest call to MAS.

    I've tried this approach, it's creating the link, but when viewing the record and the linked docs, viewing the document fails with an error.  We are not stuck with using this approach, it's just a best guess attempt.  Other approaches are welcome.

    Postman is posting to url
    https://myserver/maximo/api/script/SERVICEREQUESTADD
    the following json (note documentdata is a base64 encoded string)
    {
        "REPORTEDBY": "71311461F",
        "REPORTEDBYID": "71311461F",
        "REPORTEDEMAIL": "abc@def.com",
        "REPORTEDPHONE": "1234567",
        "DESCRIPTION": "Testing",
        "DESCRIPTION_LONGDESCRIPTION": "long description",
        "ASSETORGID": "EAGLENA",
        "ASSETSITEID": "MYSITE",
        "ORGID": "EAGLENA",
        "SITEID": "MYSITE",
        "LOCATION": "Z95",
        "DOCLINKS": [
        {
          "DOCUMENT": "test.txt",
          "DESCRIPTION": "File added by rest post",
          "URLTYPE": "FILE",
          "DOCTYPE": "Attachments",
          "ADDINFO": "1",
          "SHOW": "1",
          "PRINTTHRULINK": "0",
          "URLNAME": "test.txt",
          "DOCUMENTDATA": "MTIzNHRlc3Qy"
        }
      ]
        
    }

    ******************************************************************************

    And this is the SERVICEREQUESTADD script.  As mentioned, the SR is created, the linked doc record is created, but the file cannot be viewed using the Maximo "View Linked Docs" UI feature.

    # MAS 9 REST Automation Script
    # Accepts JSON, creates SR, logs processing, returns SR number or error

    from psdi.server import MXServer
    from psdi.mbo import MboConstants
    from java.util import Base64
    from java.io import ByteArrayInputStream
    from java.lang import Exception as JavaException
    from com.ibm.json.java import JSONObject, JSONArray

    mxServer = MXServer.getMXServer()
    responseBody = "{}"

    try:
        service.log_info("CREATE_SR_REST: Script execution started")

        if not requestBody:
            service.log_info("CREATE_SR_REST: No JSON payload received")
            raise Exception("No JSON payload provided")

        service.log_info("CREATE_SR_REST: Raw requestBody = " + str(requestBody))

        data = JSONObject.parse(requestBody)
        service.log_info("CREATE_SR_REST: JSON parsed successfully using IBM JSONObject")
        userInfo = mxServer.getSystemUserInfo()
        srSet = mxServer.getMboSet("SR", userInfo)
        sr = srSet.add()

        service.log_info("CREATE_SR_REST: SR MBO created")
        fields = [
            ""REPORTEDBY","REPORTEDBYID","REPORTEDEMAIL","REPORTEDPHONE",
            "DESCRIPTION","DESCRIPTION_LONGDESCRIPTION","AFFECTEDPERSON",
            "AFFECTEDPERSONID","ASSETORGID","ASSETSITEID",
            "ORGID","SITEID","LOCATION"
        ]

        for f in fields:
            if data.containsKey(f):
                val = data[f]
                if val is not None and str(val) != "":
                    sr.setValue(f, str(val), 11)

        # ---------------------------------------------------------------------
        # Process Attachments
        # ---------------------------------------------------------------------
        if data.containsKey("DOCLINKS"):
            docSet = sr.getMboSet("DOCLINKS")
            docArray = data.get("DOCLINKS")
        
            for d in docArray:
                filename = d.get("DOCUMENT")
                description = d.get("DESCRIPTION")
                filedata = d.get("DOCUMENTDATA")
                service.log_info(">>> Attaching file: " + filename)
                # Decode Base64
                bytesData = Base64.getDecoder().decode(filedata)
                #stream = ByteArrayInputStream(bytesData)
                document = d.get("DOCUMENT")
                description = d.get("DESCRIPTION")
                urltype = d.get("URLTYPE")
                doctype = d.get("DOCTYPE")
                urlname = d.get("URLNAME")
                filedata = d.get("DOCUMENTDATA")

                service.log_info(">>> Processing attachment: " + document)

                doc = docSet.add()
                doc.setValue("ADDINFO",1)
                doc.setValue("DOCUMENT", document)
                doc.setValue("DESCRIPTION", description)
                doc.setValue("URLTYPE", urltype)
                doc.setValue("DOCTYPE", doctype)
                doc.setValue("URLNAME", urlname)
                doc.setValue("NEWURLNAME", urlname)
                doc.setValue("DOCUMENTDATA", filedata)
                
        service.log_info("Saving SR " + sr.getString("TICKETID"))
        srSet.save()
        sr_num = sr.getString("TICKETID")
        service.log_info("CREATE_SR_REST: SR saved successfully: " + sr_num)
        responseBody = (
            '{"status":"SUCCESS","sr_number":"' + sr_num + '"}'
        )

    except JavaException as je:
        msg = str(je)
        service.log_info("CREATE_SR_REST: JavaException occurred: " + msg)
        responseBody = '{"status":"ERROR","message":"' + msg + '"}'

    except Exception as e:
        msg = str(e)
        service.log_info("CREATE_SR_REST: Exception occurred: " + msg)
        responseBody = '{"status":"ERROR","message":"' + msg + '"}'

    service.log_info("CREATE_SR_REST: Script completed")

     


    #Integrations
    #MaximoApplicationSuite

    ------------------------------
    Jose Nodeland
    JedaWorks
    ------------------------------


  • 2.  RE: Post linked document to MAS

    Posted 3 days ago

    The REST API in Maximo is extremely powerful and can handle almost any scenario, including this. Please look at utilizing that (IBM Maximo REST API Guide – Handling Attachments) rather than trying to process the message yourself. The REST API provides error handling, validation (assetnum ABC123 is not valid), actions (setting attribute A should set attribute B), security controls (restricting field access), processing (attachments can be stored as files on a file system, S3, Azure, or custom adapters like SharePoint and you need different handling for each), etc. 

    If you want, you can use the exclude attributes feature on the object structure you create to only enable the subset of fields you want to be set on the SR. 



    ------------------------------
    Steven Shull
    Naviam
    ------------------------------



  • 3.  RE: Post linked document to MAS

    Posted 2 days ago

    We use rest for some items, where it works.  I've problems with Maximo rest because a lot of the documentation is wrong, incomplete or vague, and samples that do not work.  And when things do not work, it's a black box that is difficult to troubleshoot.
    ------------------------
    Example of wrong documentation, all the docs use GET /oslc/os/mxapiasset, which does not work for mas (at least does not work for us), one has to use api/os not oslc/os.  

    -------------------------------

    Example of vague documentation, "https://ibm-maximo-dev.github.io/maximo-restapi-documentation/attachment/attachment/" says "

    1. Enable the attachments feature.", what is that supposed to mean.  Basic out of the box doclinks configuration or??

    ----------------------------

    Example of a "black box" error, the first example at https://ibm-maximo-dev.github.io/maximo-restapi-documentation/crud/create_and_update

    says:
    POST /oslc/os/mxapiasset
    Post body:

    { "assetnum": "ASSET1", "siteid": "BEDFORD", "description": "my first asset" }


    Using postman to perform the post (after changing the url to api/os), the following error is thrown "Site id cannot be null".  Makes no sense to us why that error is thrown, siteid has been supplied.

    --------------------------------------------

    I can give many such samples. Eventually we quit wasting time trying to figure out the rest black box and try something else.



    ------------------------------
    Jose Nodeland
    JedaWorks
    ------------------------------



  • 4.  RE: Post linked document to MAS

    Posted 2 days ago

    The /oslc vs /api is covered here (IBM Maximo REST API Guide – Interfacing with REST apis using API keys) though I understand the confusion. /oslc is valid and utilized even in MAS by the mobile product, the new role-based applications, etc. It all depends on how authentication occurs. When you need to utilize an API key for authentication, you use /api. When you authenticate with the x-access-token, LTPA token, etc. you utilize /oslc. Since the majority of customers are not trying to implement authentication in the integrations calling the API, and fewer customers are running 7.6, it would probably be better to get the documentation updated to assume use of an API key and the api route. 


    Regarding the "enable the attachments feature", I agree that is extremely vague and shouldn't exist in this context. The intent here was to state that inside of Manage, you need to configure doclinks (setting the system properties to point to the S3/file system, setting up doctypes, etc.). That's part of core Manage installation and shouldn't really be covered in the REST API documentation (in my opinion). The important part to the REST API is the line below which is you need to ensure that the doclinks object is part of your object structure. It's also not clear here but you need to ensure the DOCUMENTDATA non-persistent attribute is included on that object structure as well if you intend to retrieve & submit it inline as part of the record creation (the /doclinks example does not require documentdata to be included). 

    Your last example is bad documentation where it is missing the ?lean=1 query parameter. IE instead of /oslc/os/mxapiasset it should be /oslc/os/mxapiasset?lean=1. That's on some examples but is missing on a lot of them. I don't want to get too confusing but there are effectively two APIs on the /oslc context. There is the OSLC API (a standard IBM developed that legacy mobile products like Maximo Anywhere utilized) and the new JSON API. The framework distinguishes between the two by lean=1 (new JSON API) or lean=0 (which is the default if omitted, the old OSLC API). The reason you get the siteid error is the OSLC standard dictates namespaces that require prefixes on attributes. Without the prefixes in the message body or the lean=1 query parameter, Maximo doesn't see the attribute. 

    I'll reach out to some of my former colleagues to see if we can make some of these fixes to make the documentation clearer. 



    ------------------------------
    Steven Shull
    Naviam
    ------------------------------