API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Complex JSON object in API string

    Posted Mon December 16, 2024 09:39 AM

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


  • 2.  RE: Complex JSON object in API string

    Posted Tue December 17, 2024 12:45 AM
    This forum is for IBM API Connect, I think you might want to find a Maximo forum for help there.
    Unless otherwise stated above:

    IBM United Kingdom Limited
    Registered in England and Wales with number 741598
    Registered office: Building C, IBM Hursley Office, Hursley Park Road, Winchester, Hampshire SO21 2JN





  • 3.  RE: Complex JSON object in API string

    Posted Tue December 17, 2024 01:29 AM

    My appologies ... i thought this is a forum for all IBM products

    For which IBM products is this forum then?



    ------------------------------
    Jan-Willem Steenbergen
    ------------------------------



  • 4.  RE: Complex JSON object in API string

    Posted Tue December 17, 2024 01:33 AM

    IBM API Connect



    ------------------------------
    Chris Dudley
    ------------------------------



  • 5.  RE: Complex JSON object in API string

    Posted Tue December 17, 2024 01:39 AM

    aah ... this is a seperate product?

    i thought it was the same API connect as in the integration application of IBM Maximo

    apologies again



    ------------------------------
    Jan-Willem Steenbergen
    ------------------------------