0

I would like to add a REST route that would looks like

.../v1/import/?url=XXX

where XXX is an URL.

I had a try with

register_rest_route('.../v1','import/?url=(?:/(?P<url>\w+))?', array(
        array(
            'methods'             => WP_REST_Server::READABLE,
            'callback'            => array( $this, 'import_url' ),
            'args' => array(
                'url' => array(
                    //'validate_callback' => array($this, 'validateImportUrl')
                ),
            ),
        )
    ) );

but it does not work:

{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}

Can anyone help ?

Thanks !

| improve this question | | | | |
  • Query parameters don't belong in the route, they should be added as arguments, which you've already done. – Jacob Peattie Jun 20 '19 at 1:40
-1

Regex problem, I found out :)

register_rest_route( '.../v1', 'import(?:/?url=(?P<url>\d+))?', array(
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.