Request Body transform is not working for me if it's together with a method transform from GET to POST

I noticed that if a request has an empty body, the body transform is ignored.

For example, to make it works with a post request the body must be at least {}.

Does that means the body transform can’t work together with a method transform from GET to POST?

For example in this api definition:

    "extended_paths": {
        "transform": [
            {
                "template_data": {
                    "input_type": "json",
                    "template_mode": "blob",
                    "enable_session": false,
                    "template_source": "ewogICJGb28iOiAiYmFyIgp9"
                },
                "path": "foo",
                "method": "POST"
            },
            {
                "template_data": {
                    "input_type": "json",
                    "template_mode": "blob",
                    "enable_session": false,
                    "template_source": "ewogICJGb28iOiAiYmFyIgp9"
                },
                "path": "foo",
                "method": "GET"
            }
        ],
        "method_transforms": [
            {
                "path": "foo",
                "method": "GET",
                "to_method": "POST"
            }
        ]
    },

the template content is:

    {
      "foo": "{{._tyk_context.request_data.foo}}"
    }

It works on the POST request if I include at least an empty body object but it’s ignored in the GET request (with both having a foo=bar query).

The same happens with any other template, even with a very simple:

  {
    "foo": "bar"
  }

Hello!

Which version you are currently using?

@Josh @Luan this looks like a known bug, do you recall if it was already fixed in previous patch releases or upcoming one?

Thank you.

Hi Leon, thank you so much for the speedy reply.

It’s tyk could that I don’t know which version is running.

I just noticed that same happens with the test form in the dashboard. If the input is {} it works, if it’s emtpy it doesn’t.

Any ETA to see this fixed on Tyk cloud?

I’d like to develop there before eventually move to Tyk hybrid and that fix it’s crucial for me.

Thank you.

Should be fixed with upcoming patch release planned this week Fix body transform when initial body is emtpty by buger · Pull Request #1576 · TykTechnologies/tyk · GitHub

Cheers!

1 Like

Released to both cloud and on-premise Tyk Gateway 2.5.4 and Tyk Dashboard 1.5.4

Now this works also with empty body, but “method transform” doesn’t work anymore.

A simple endpoint with only a method transform from GET to POST is not transformed.