Using context variables in URL rewrite

I want to use a single value from multiple URL-Parameters in URL Rewrite.

Input URL is like:

http://my.api/endpoint?param1=value1&param2=value2

that should be rewritten as

http://external.api/endpoint/value2

I activated context variables for my API on so I get $tyk_context.request_data filled correctly, but how to access the single value for param2 when request_data is “param1:value1;param2:value2”

I tried the following rewrite templates:

customer-groups/$tyk_context.request_data.value2 -> …/endpoint/param1:value1;param2:value2.value2
customer-groups/$tyk_context.request_data[param2] -> …/endpoint/param1:value1;param2:value2.[param2]

You could just use a standard URL rewrite?

URL Pattern: endpoint?{params}
Match: (param2=)(\w+)$
Rewrite: endpoint/$2

Nice sandbox example: http://regexr.com/3ema8

oh, thanks. of cause that will work. Didn´t think about that :slight_smile:

but anyway, would there be a possibility to access a single value from the context variable?

the same question would apply to body transform as I would like to inject a parameter value into the body data

In the URL rewriter - not yet
In the body transform I think you can use dot notation.

yes, in the documentation for body transform it is mentioned, that this is only possible here and not for URL rewriting