No parameters coming through when testing WebDev doPost?

I have set up the following web dev resource for doPost:

def doPost(request,session):
	logger = system.util.getLogger("ERP_Integration")
	scriptName = 'Web Dev/volCompliance/doPost'
	authProfile = "ERP_Users"
	currDate = shared.util.getGatewayDateTime()
	currDateStr = system.date.format(currDate,"yyyy-MM-dd HH:mm:ss")
	
	logger.info(scriptName + ' - inbound httpPOST request detected')
	logger.debug(scriptName + ' - session data: %s' % (str(session)))
	logger.debug(scriptName + ' - parameters: %s' % (str(request['params'])))
	logger.debug(scriptName + ' - headers: %s' % (str(request['headers'])))
	####logger.debug(scriptName + ' - data: %s' % (str(request['data'])))
	
	
	#------------------ Get request parameters -----------------#
	# if application/json data is used inbound, access like this:
	# param = request['params'].get("paramName")
	groupID = request['params'].get("pfmGroupID")
	gradeID = request['params'].get("pfmGradeID")
# end def

I am building a test function as follows:

def test_incomingPOST():
	scriptName = "shared.api.test_incomingPO"
	logger.info(scriptName + " - script started")	

	url = "http://myhostname:8088/main/system/webdev/ERP_Test/volCompliance"
	params = {"pfmStartDate":'2022-08-20 00:30:00',"pfmEndDate":'2022-08-27 10:30:00',"pfmGroupID":"GROUP1","pfmGradeID":"-ABC","pfmThickID":"50","pfmWidthID":"200","pfmLengthID":"4050","pfmVolume":"0.457","pfmLocationID":"WDM"}
	jsonMsg = system.util.jsonEncode(params)
	
	response = system.net.httpClient().post(url=url,params=params)
	###response = system.net.httpPost(url,contentType="application/json",params=jsonMsg, throwOnError=True)
	####logger.info(scriptName + " - response status: %s" % response.statusCode)
	
	return system.util.jsonDecode(response.json)
	###return system.util.jsonDecode(response)
# end def

When calling this test function, the output of my logger is showing there are no parameters.
I’m going a bit nuts here, can someone point out where i’m going wrong sending parameters to the endpoint?
I’ve tried both the system.net.httpClient and system.net.httpPost in-built functions, both providing same issue.

You should be looking at the data or postData, not params. params are URL parameters, not a request body.

Edit: errr n/m, you’re posting with params too… Hmm

What’s under here?

That is just an error telling me there is nothing when i try to access parameters via:

groupID = request['params'].get("pfmGroupID")

and then try and use groupID somewhere. It complains about it being None.

Ok so tried to dumb it down a bit, and got some partial success. but something still seems fishy…

Simplified the function call to this:

response = system.net.httpPost(url, {"pfmGroupID":"13456"})
print system.util.jsonDecode(response)

When there were other issues inside the WebDev endpoint, i got the following exception, which finally implied i was sending the parameter in the URL:

IOError: Server returned HTTP response code: 501 for URL: http://172.20.7.94:8088/system/webdev/ERP_Test/volCompliance?pfmGroupID=13456

What has thrown me for a loop is the logger showing the value and type of the parameter passed through:

ERP_Integration	16Aug2022 10:17:24	Web Dev/volCompliance/doPost - inbound httpPOST request detected
ERP_Integration	16Aug2022 10:17:24	Web Dev/volCompliance/doPost - data: array('b')
ERP_Integration	16Aug2022 10:17:24	Web Dev/volCompliance/doPost - headers: {'Cookie': u'JSESSIONID=node02o79ir60n77cqp8spcouz1ct64.node0', 'Accept': u'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2', 'User-Agent': u'Java/11.0.15', 'Connection': u'keep-alive', 'Host': u'172.20.7.94:8088', 'Content-Length': u'16', 'Content-Type': u'application/x-www-form-urlencoded'}
ERP_Integration	16Aug2022 10:17:24	Web Dev/volCompliance/doPost - parameters: {'pfmGroupID': (u'13456', u'13456')}
ERP_Integration	16Aug2022 10:17:24	Web Dev/volCompliance/doPost - session data: {u'user': {badge=null, schedule=Always, firstname=SAP01, notes=Test user for SAP inbound connections, language=en, user.pin=, username=SAP01, lastname=null}}
ERP_Integration	16Aug2022 10:17:24	

Why would the pfmGroupID parameter be a tuple now…?

Does the same thing happen if you use system.net.httpClient instead?

I did observe a small error in our docs page for system.net.httpClient() regarding redirect_policy. It defaults to “NEVER” (not “NORMAL”) when unspecified. That is now corrected.

I think you’re probably going to run into problems trying to send all of that through as URL parameters. It seems more apropos to do a POST with a request body. That said, I was able to mock this up successfully:

If your params entries have spaces in them (or other special characters), you’ll probably encounter errors such as:

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Illegal character in query at index 106: http://...

Let me check...

And another discovery... probably obvious to someone who deals with HTTP requests a lot, but the reason my parameters weren't getting sent to the endpoint correctly was due to invalid formatting of the date variables. It seems obvious in hindsight, but you cannot send a parameter string that looks like this:

IOError: Server returned HTTP response code: 400 for URL: http://172.20.7.94:8088/system/webdev/ERP_Test/volCompliance?pfmWidthID=200&pfmLengthID=4050&pfmStartDate=2022-08-20 00:30:00&pfmVolume=0.457&pfmLocationID=WDM&pfmGradeID=-ABC&pfmEndDate=2022-08-27 10:30:00&pfmGroupID=GROUP1&pfmThickID=50


Happy days if you format the date strings in a more URL friendly way such as:

?pfmWidthID=200&pfmLengthID=4050&pfmStartDate=2022-08-20&pfmVolume=0.457

Or i'm sure there are industry standards such as:

date=2012-12-31T22:00:00.000Z .

Agreed.

And I ask about system.net.httpClient instead because system.net.httpPost seems to always send the provided parameters as body, not URL parameters.

Yes that was the problem… funny characters in the URL.

I would like to do a POST with request body but i seem to have forgotten how to do that. I think i did it in Javascript in some other project, but struggling a bit atm to recall it.

Just supply a data parameter instead of params when using system.net.httpClient

Also, if you do want to use URL params, system.net.httpClient will encode them for you, as long as the params object you provide is a dictionary and not pre-encoded JSON like you were doing. If you encode it yourself you are responsible for URL escaping the contents.

Ok, and presumably if using system.net.httpPost, using the postData and sending as a json encoded string does the equivalent?

Struggling to get system.net.httpClient working at the moment but i think i have enough to go by at the moment.

EDIT: Managed to get the data coming in properly using httpPost, and postData. Values no longer coming through as tuples like they did when sent as URL parameters…
I vaguely remember this being an issue on my other project too actually…

Thanks for the help guys.