Thread Starter
ysnz
(@ysnz)
Thanks for your answer!
I thought I tried this too, but I was too confused 😀
So here the working code for everybody else who wants a working code to start with.
$request = new WP_REST_Request( 'POST', '/redirection/v1/redirect' );
$request->set_param('status', 'enabled');
$request->set_param('position', 0);
$matchdata = ['source' => [
'flag_regex' => false,
'flag_query' => 'ignore',
'flag_case' => true,
'flag_trailing' => false
]];
$request->set_param('match_data', $matchdata);
$request->set_param('regex', false);
$request->set_param('url', '/here-we-come');
$request->set_param('match_type', 'url');
$request->set_param('title', 'test2');
$request->set_param('group_id', 1);
$request->set_param('action_type', 'url');
$request->set_param('action_code', 301);
$request->set_param('action_data', ['url' => '/here-we-go']);
$response = rest_do_request( $request );
$server = rest_get_server();
$data = $server->response_to_data( $response, false );
// do whatever you want with the returned data