httpClient PUT Not responding as expected

I am tying to utilize the system.net.httpClient() to send a request to an API. The API is setup to use a PUT for us to retrieve data based on an accompanying JSON payload.
Unfortunately my code only ever returns a Server Error (500) and the exception java.lang.NullPointerException.

Below is the function I've written to interface with the API.

def getQADAPIDataForRun(url, payload):
        apiParams 		= payload
        apiRunData 		= None #init API run data
        qadresponse		= None
        qadURL 			= url
        try:
            qadClient 		= system.net.httpClient()
            qadresponse		= qadClient.put(url=qadURL, data=apiParams)
            if qadresponse.good:
                apiRunData 	= qadresponse.json['items']
                runDataValid 	= True
            elif qadresponse.clientError:
                runDataValid 	= False
                msg = 'Client Error Occured: {}.'.format(qadresponse.clientError)
                print(msg)
            elif qadresponse.serverError:
                runDataValid 	= False
                msg = 'Server Error Occured: {}.'.format(qadresponse.serverError)
                print(msg)
            else:
                runDataValid 	= False
                msg = 'OTHER Error Occured.'
                print(msg)
        except Exception as e:
            #raise an exception
            runDataValid 	= False
            msg = 'An Exception Occured: {}'.format(str(e))
            print(msg)
        return runDataValid, apiRunData, msg, responseRequest

The above is being called from the Script Console.
I can successfully get a response from the API using Postman's PUT method to the URL, providing the raw JSON string.

I would have thought the team creating the API would have developed a GET method since we are getting data from the API. My knowledge of Web stuff is rudimentary at best, so maybe my understanding of GET/PUT methods are incorrect. Will the httpClient PUT method work in this case? Is there anything glaringly wrong with my function?

The URL being passed in to the function is the same as used in my Postman test, so I am confident in it. The "easy to read" payload being provided to the function is as follows:

{
    "request": {
        "ds_rundata": {
            "RunInfo": [
                {
                    "RI_domain": "US1",
                    "RI_run_id": "R1000907"
                }
            ]
        }
    }
}

The actual payload string is,
{"request":{"ds_rundata":{"RunInfo":[{"RI_domain":"US1","RI_run_id":"R1000907"}]}}}"
The API development team is using Insomnia to test their API, and it gets the same results as my test using Postman. So that indicates there is something wrong with the content I've developed. As noted, my less than stellar Web knowledge is likely what is preventing me from seeing my mistake(s), so any help would be appreciated.

Is the payload variable a String containing JSON or is a dictionary object?

It is a JSON string. I used the jsonEncode function to convert a dictionary to json for this purpose.

If it's already a String at that point then you probably aren't providing the expected Content-Type header, which is going to be text/plain because you are providing a String as the data param.

Maybe set it to application/json in the headers map? Or try providing a dictionary object, which the client will encode to JSON for you and set the correct header value.

I have to update this as my previous statement was not accurate. :frowning:

Both paths, adding the header map or passing in the dictionary, resulted in the same output. The response is GOOD, but I have not tried parsing any response data. If I still have issues, I will return to this thread and query further.

Thank you Kevin for your help. I think you have put me on the right track! :+1: