Maximo Open Forum

 View Only
  • 1.  Python 3.9 code for executing OSLC JSON Rest API

    Posted 09-27-2021 18:50
    Edited by Pankaj Bhide 09-27-2021 19:25
    Hello, 

    I am trying to develop a python 3.9 program (that we plan to execute externally) that performs HTTP Get from the object structure related to person and displays the JSON returned from MAXIMO.

    Please see the simple code below;

    =================
    from pprint import pprint
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
    from urllib.parse import urlparse
    import requests
    import base64
    from lblpycommon import lbl_libutil01

    #-- ignore bad ssl
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


    strObjectStructure="lbl_ds_person"
    strAutomationScript=None
    strListofColumns="personid,firstname,lastname,displayname,location,supervisor,lbl_status,lbl_org_level_1,lbl_org_level_2,lbl_org_level_3"
    strWhere="lbl_org_level_1=%22IC%22"
    strSavedQuery=None

    # Get the MAXIMO URL from properties file
    if (strAutomationScript==None):
        strUrl=lbl_libutil01.getPropertyValue("maximorestoslcurl")+"/"strObjectStructure
    else:
        strUrl=lbl_libutil01.getPropertyValue("maximorestoslscriptcurl") +"/"strAutomationScript

    # Prepare Headers
    dictHeaders = {
     #'maxauth': maxauth, # BASIC auth = login:passwd
     'Accept'"application/json",
     'Content-Type'"application/json",
     'Allow-Hidden'"true",
     }

     # Prepare parameters
    dictParams = {
     'lean':1# Remove name space - recomended when working with Maximo JSON
     'oslc.select''personid,firstname,lastname,displayname,location,supervisor,lbl_status,lbl_org_level_1,lbl_org_level_2,lbl_org_level_3',
     'oslc.where'"location='069-0102D'",
     'oslc.pageSize':1,
     'apikey':'*********'
     }
    r = requests.get(strUrlheaders=dictHeadersparams=dictParamsverify=False)
    pprint(r.json())
    ==============================
    My questions are ;

    1) How to specify the "where clause" that contains something like location='069-0102D'. The line " 'oslc.where'"location='069-0102D'" gives error. I tried "location=%22069-0102D%22". However that is also not working. 

    2) For example ;
      'oslc.where':'assetnum=Myasset111',   -- it is not working. i tried "assetnum='%22Myasset111%22" etc.

    also how to check for wildcard searches?

    Also how to specify "or" "and" operators 

    For example:
     'oslc.where':'assetnum=Myasset111 or location=90F

    Appreciate any help.




    #Customizations

    ------------------------------
    Pankaj Bhide
    Berkeley National Laboratory
    ------------------------------


  • 2.  RE: Python 3.9 code for executing OSLC JSON Rest API

    Posted 09-28-2021 09:03
    Use double-quotes around string literals in the oslc.where clause. For example:

    'oslc.where': 'assetnum="11430" and siteid="BEDFORD"'

    For wildcard searches, use the asterisk * symbol. For example:

    'oslc.where': 'siteid="BEDFORD" and manufacturer="*"'

    Hope this helps,

    ------------------------------
    Alex Walter
    A3J Group, LLC
    ------------------------------