REST Resource validation on a custom form


(James) #1

[Squiz Matrix v5.4.3.1]
Hi, I’ve noticed when I turn on the validation on a form that calls a REST API it’s stopping the request body being formed correctly. It’s preventing keywords being used. For example {“name”:" %response_182102_q1% "} only works when validation is turned off. Is this a bug? I need to submit the request body with this data and then evaluate the response body to see if it worked. Hope that makes sense?

Ref: https://matrix.squiz.net/manuals/custom-form/chapters/submission-actions-screen#call-rest-resource_validation-rule


(Bart Banda) #2

Hmm, that definitely sounds like a bug. Could you share some more information about the whole implementation here for us to review further and try and replicate?


(James) #3

Hi Bart, I’m trying to upload files and data from a Squiz form into another application that has a REST API with several GET and POST submission actions. If I don’t use the validation on the squiz form (REST Resource) it works fine and the files and data end up in the other application as they should.

Normally if there’s a problem with the upload the API I call sends either a HTTP status code or JSON with the value ’ failed’ that I would capture with the validation rule and display an appropriate error message.

However when I turn the Squiz REST Resource validation on it appears to capture the response code sent back by the API of the application I’m calling, showing my custom Squiz form validation error message. By ticking the validation box it doesn’t convert the %keyword% into a real value and so I upload nothing, hence the error I get back from the API.

The details are:

POST with basic authentication, never cache.

Content-Type: multipart/form-data;boundary="boundary"

–boundary

Content-Disposition: form-data; name="upload1"; filename="CMSUpload_1_%response_182102_q2_file_id%"

%response_182102_q2_file_contents%

–boundary

The validation rule is:

One of response bodies must match a regex (Draft saved successfully)

If validation turned on then _%response_182102_q2_file_id%" in the request body does not get converted to a value, in this case the asset id of the uploaded file. If turned off it works, but then I have no mechanism to capture errors passed back from the back-end application.

The same is true if the request body I pass is just JSON, e.g. request headers of content-type: application/json, and request body being {“name”:"%response_182102_q1%"}

Hope that makes sense?

Cheers James


(Bart Banda) #4

Thanks James, that helps a bit more.

We’ll try and see if we can replicate this in the latest version of Matrix and report back here. In the meantime, if you are a Squiz client, I suggest sending a support ticket in to see if we can’t have a closer look at the implementation through that and get some more info that way, and potentially supply a custom patch.


(James) #5

Hi Bart, Thanks for responding. I’ll raise a support ticket and reference this topic. James