Juuso Lepistö · Nov 5, 2021

ERROR #9406

I'm trying to send a POST request to my REST API and I'm getting this error and most likely due the lack of experience, I have no idea how to fix this issue:  

"error": "ERROR #9406: Unexpected format for value of field, AlertText, using class base mapping",

            "id": "JSONImportError",

            "params": [


                "class base"


Am I missing something from my string definition?

Defined below as:

Class User.RESTComponents Extends (%Persistent, %JSON.Adaptor, %Populate)


Property AlertText As %String;


Here is my POST -method:

/// Creates a new User.RESTComponents item

ClassMethod POSTService() As %Status


    #dim tSC As %Status = $$$OK

    #dim e As %Exception.AbstractException

    Set test = ##class(User.RESTComponents).%New()

    Set data = %request.Content




    Set %response.Status = 204

    Set %response.ContentType = ..#CONTENTTYPEJSON

    //d data.%ToJSON()

    Do test.%JSONExport()


    Quit tSC


Product version: IRIS 2021.1
0 158
Discussion (4)2
Log in or sign up to continue

Okay, so I figured out that I was missing a little more code from my POST -method

Needed to change: 

Set data = %request.Content ==> Set data = {}.%FromJSON(%request.Content)

This got me past my previous error and to the next one, which is as follows:

"ERROR #5035: General exception Name 'READ error while reading input stream' Code '10' Data ''"

“AlertText” is not the name of a JSON object field but is instead the value of a JSON array element.  Assuming you have done your %FromJSON into variable ‘data’ then data.%Get(“params”).%Get(0) will evaluate to the string value “AlertText”.

So I added a parameter to the same file, where all my methods (post, get etc.) are located:

HandleCorsRequest = 1;

And changed: Set data = {}.%FromJSON(%request.Content) back to Set data = %request.Content

Now my POST method suddenly works. I don't know how or why, but its works.