Anyone has experience with inserting JSON in API headers?
i hjave no idea how to include this header with the correct escape characters
in postman it is working, but as soon as i send it with Maximo the server does not understand it anymore
key : tsGenListViewParams
Value: {"tsDisplayType":"dtList","tsParentId":5909237214,"tsProjects":"5909236975","tsEtpIds":"790", "fields":"id,name,description"}
in my script it looks like this
## serialiser
def dict_to_json(data):
"""
Eenvoudige JSON-serializer voor dictionaries.
"""
import re
json_string = '{' + ', '.join(
'"{}": {}'.format(k, '"{}"'.format(v) if isinstance(v, str) else v)
for k, v in data.items()
) + '}'
return json_string
# start logging
myLogger = MXLoggerFactory.getLogger("maximo.script.customscript")
myLogger.error("##### Start Topteam")
# 1. build complex JSON-string
json_data = {
'tsDisplayType': 'dtList',
'tsProjects': '5909236975',
'tsFilterType': 'ftFilterCondition',
'tsFilterValue': '"ID" IN LIST "BB-15583"',
'fields': 'id,name,description'
}
# serialise
json_string = dict_to_json(json_data)
#set headers
headers = {
"Authorization": "Basic {key}",
"tsGenListViewParams": json_string
}
# send request
endpoint = "https://topteamdemo2.synergio.nl/rest/ttmrestsrv.dll/2.0/ByRecordType/REP"
url = URL(endpoint)
conn = url.openConnection()
conn.setRequestMethod("GET")
conn.setRequestProperty("Authorization", headers["Authorization"])
conn.setRequestProperty("tsGenListViewParams", headers["tsGenListViewParams"])
# add header
conn.setRequestProperty("Content-Type", "application/json")
------------------------------
Jan-Willem Steenbergen
------------------------------