Hi Scott,
Thank you for taking the time to reply, and sorry for the delay. I kept checking back, but something seemed to be going on with the site. I really appreciate your patience.
I left out some details initially, thinking they wouldn’t matter, but maybe they will help now. I’ll admit, while HTTP isn’t exactly new territory for me, CCSID handling definitely is. Normally I just get things working by relying heavily on documentation (especially yours!), and I haven’t really had to dig into CCSID intricacies — until now.
In this project, we asked a vendor to call an external API (parcel shipper) by sending JSON data (so the code in question isn’t mine). I was reviewing their implementation and pointing out a few things based on my understanding — mostly just thinking out loud. My boss even reminded me that I don’t always have to be the hero.
Here’s the situation:
* We are building a JSON string using YAJL, then assigning it to the HTTP request variable.
* The API owner claims they can accept special characters like `ñ`, but when such characters are present, we get a "Bad Request" error with no further details.
* Their only suggestion was “I think it needs to be escaped,” but they didn’t sound very confident, so I’m not sure they truly understand the issue.
Regarding the code:
Code: Select all
yajl_copyBuf(0:x_stream:10000:retsize);
You’re correct — this line isn’t from YAJL itself, but rather in the wrapper program calling the YAJL procedures to build the JSON.
Initially, we used `0` for the CCSID, which I now understand means “convert to the job’s CCSID.” Since our job is running under CCSID 37 (EBCDIC), I suspected that might be why the n-tilde (`ñ`) wasn’t making it through properly. To test this, I changed the CCSID to 1208 (UTF-8), which did bypass the “Bad Request” error, but the API response came back as an HTML error page — not the expected ZPL.
Here’s a subset of what the request body looked like when viewed in the log:
I recognize that this is probably due to CCSID mismatch between the stream (UTF-8) and the log viewer (819), so that’s understandable.
The response we received was a 500 error with an HTML body like this:
Code: Select all
<title>We're sorry, but something went wrong (500)</title>
<p>If you are the application owner check the logs for more information.</p>
So while changing the CCSID did result in the request being accepted, it seems like the JSON may still have issues (possibly invalid formatting or quoting), or the API itself can’t handle some aspect of the content.
I definitely plan to try your suggestion of writing the JSON to a file and sending that instead — that might help isolate the issue or at least confirm how the data is being constructed and encoded.
Thanks again for your help and your patience while I wrap my head around all of this.