Custom WP rest api endpoint only working on non https?

I'm googling like an hour for a possible solution while im trying to create my first custom wordpress rest api endpoint.

If i call the endpoint by postman it just works, but if i try with jquery, it doesn't.

I noticed, that if i call it by the http version it works, but on https it just returns 404?

Heres my endpoint registration:

add_action('rest_api_init', function () {
  register_rest_route('the-namespace/v1', '/the-endpoint', [
    'method' = WP_REST_Server::CREATABLE,
    'callback' = 'theEndpoint',
    'permission_callback' = function () {
      return true;
    }
  ]);
});

function theEndpoint(WP_REST_Request $request)
{
  $data = [
    'some' = 'data',
  ];

  $res = new WP_REST_Response($data);
  $res-set_status(200);

  return [$res];
}

And the corresponding js ajax code:

var data = {
  unusedData: 'so far',
};
jQuery.ajax({
  method: 'POST',
  url: '/wp-json/the-namespace/v1/the-endpoint',
  data: data,
  dataType: 'json',
  contentType: 'applcation/json',
  success: function(data, status) {
    alert(Data:  + data + \nStatus:  + status);
  }
})

Sure i googled and tried to compare what postman is doing differently, but maybe i'm overlooking something?

Thanks for your time!

EDIT - more info:

  • Permalinks have been flushed
  • Site (Wordpress Adress and Site Adress) is configured HTTPS
  • It's the full example code
  • I noticed, that i can actually register the same thing as get and it works. Only the post style registration doesnt work.

EDIT - htaccess (not from me..) I just created a link to view the htaccess file, I don't know if it's too big for here, so i pasted it on pastebin - here.

Topic endpoints rest-api ajax jquery Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.