使用 Maximo REST API 创建 Object Structure

发布于:2024-05-08 ⋅ 阅读:(26) ⋅ 点赞:(0)

接前面的文章,今天通过编写Python脚本的方式使用 Maximo REST API 创建Object Structure。

创建 object structure

这里创建一个新的 Work Order Object Structure,命名为 MXAPIWO123。

import requests

url = "<maximo url>/api/os/mxintobject"

querystring = {
    "apikey":"<api key>",
    "lean":"1"
}

payload = """{
    "intobjectname": "MXAPIWO123",
    "description": "Maximo API for Work Orders",
    "usewith": "INTEGRATION",
    "module": "WO",
    "authapp": "MXAPIWO",
    "maxintobjdetail": [{
            "objectname": "WORKORDER",
            "hierarchypath": "WORKORDER",
            "objectorder": 1
        },{
            "objectname": "WORKLOG",
            "hierarchypath": "WORKORDER/WORKLOG",
            "parentobjname": "WORKORDER",
            "relation": "MODIFYWORKLOG",
            "objectorder": 1
            }
        ]
    }"""

headers = {
    'user-agent': "vscode-restclient",
    'content-type': "application/json",
    'properties': "*"
}

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

运行脚本

python create.py | json_pp

查看 object structure

import requests

url = "<maximo url>/api/os/mxintobject"

querystring = {
    "apikey": "<api key>",
    "lean": "1",
    "oslc.where": "intobjectname=\"MXAPIWO123\"",
    "oslc.select": "*" 
}

headers = {
    'user-agent': "vscode-restclient",
    'content-type': "application/json"
}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

运行脚本

python info.py | json_pp

使用 object structure

这里使用上面创建的 MXAPIWO123 Object Structure 查询 Work Order 数据。

import requests

url = "<maximo url>/api/os/MXAPIWO123"

querystring = {
    "apikey": "<api key>",
    "lean": "1",
    "oslc.pageSize": 10,
    "oslc.select": "*" 
}

headers = {
    'user-agent': "vscode-restclient",
    'content-type': "application/json"
}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

运行脚本

python query.py | json_pp

网站公告

今日签到

点亮在社区的每一天
去签到