This topic is locked

REST API requires PATCH requests to have Content-Type : application/json-patch+json

10/20/2021 3:23:45 PM
PHPRunner General questions
jshroads author

Working on an update function (list and single work)
When I try and set the Content-Type to application/json-patch+json, and then run the request I get an error :Return code: 500

[{"ok": false,"error": "InternalServerError","field": null,"message": "Error processing request."} ]

If I use application/json, the request says it works, but the data is not updated. This behavior is identical in Postman, so issue is I must use application/json-patch+json.
Any workaround or ideas?

img alt

admin 10/20/2021

PHPRunner doesn't support application/json-patch+json content type, but it shouldn't be a problem for you.
Just skip the 'Run request' part, it is not needed with update operation.

To make the generated application support application/json-patch+json type do the following.
After building the project open the generates classes/datasource/httprequest.php file with a text editor.
Locate this snippet there:

if( $type == "application/json" ) {
return my_json_encode( $this->postPayload );

and replace it with

if( $type == "application/json" || $type == "application/json-patch+json" ) {
return my_json_encode( $this->postPayload );

You can apply the same changes to the file in <PHPRunner installation directory>\source to make them permanent.
We'll add "application/json-patch+json" support with the next update of PHPRunner.