404 errors with API

Hello,

i can use : /wp-json/mainwp/v1/sites/all-sites
it works well

but when i try to use :

/wp-json/mainwp/v1/sites/get-sites-by-url
or
/wp-json/mainwp/v1/site/add-site

i have this error :

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

I’m using th the same key/secret.

Is there any error logs for that ?

PS : i’m using PostMan (on Windows 10) and Make.com to test the API. Both are working with /all-sites and both are not working with the other requests. (always the same 404 error)

Thanks for your help

@Info1 Thanks for reaching out - We will have a look into things to see if we can replicate the issue that you are having.

1 Like

Hi Keith, thanks !

I tried to :

  • deactivate Wordfenced + itheme security
  • deactivated cloudflare
  • both GET and POST
    without success

@Info1 Thank you very much for the updated flow - I have confirmed what you have reported and we are looking into the issue. We will post our HOTFIX here once we have solution.

Thanks for your patience.

I actually can’t duplicate the issue.

I just tested the /wp-json/mainwp/v1/sites/get-sites-by-url endpoint with Postman and it works for me.

Please see here:

Can you please check and verify that the Content-Type header is set to application/json in headers settings:

2 Likes

Hi, thanks!

I still have the 404

What’s also troubling me, is that “sites/get-sites-by-url” route is not existing when i check :
/wp-json/mainwp/v1

Hi @Info1,

Can you please try with this version:

The /get-sites-by-url endpoint is not included in the current live version. This is something that we have set for the upcoming release. But since the help document got updated before the release, seems that this caused the confusion.

1 Like

Thanks @bogdan , ok so that’s the reason why, obviously :slight_smile:

i don’t understand how people can use the API in a simple way without /get-sites-by-url ? It’s the only simple way to get a specific site ID and use the other API entries. (which all requires the site ID)

entry request : get-sites-by-domain would be cool too. Ie domains=test.com , and will match even if url is “https://www.test.com” or “http://test.com:wink:

And another api request would be : the possibility to use “domain.com” instead of “Site_id” for all site entries.

Because when we manage websites outside of mainwp, our databases column always have domain.com, but we usually don’t know the MainWP site_id, so querying the api means we will have to always first run a first api call to find the site_id.

Hi @Info1,

thanks for your feedback. We appreciate that.

MainWP v1 REST API doesn’t have support for all possible features and ways to handle information. But we are planning to extend it as our users needs grow.

Please feel free to post your suggestion on feedback.mainwp.com so we don’t lose your suggestion and other users can support it.

2 Likes

About the zip file, how safe it is ? I’m managin +80 sites… not sure if i want to experiment stuffs here :slight_smile:

About the production api, it seems the documentation is not accurate,
do you know if the add-site entry is working ? I can’t make it work here.

It’s as trust worthy as any of our releases. This endpoint was included in the version just released today.

As already stated the documentation was updated prior to the release.

Pleaae update your MainWP environment to the latest versions and the endpoint should work.

1 Like

Ok, that’s great, just got the last release and /wp-json/mainwp/v1/sites/get-sites-by-url is working ! Thanks a lot !

I stil have the issue with “add-site” from the API :

i wonder if
mainwp/v1/site/add-site/
is working ?

i keep having the error “{
“error”: “MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the <a href="https://managers.mainwp.com/c/community-support/5\” target="_blank">MainWP Community for help.”
}"
but when i use the exact same data to add the site using MainWP interface (through /wp-admin/admin.php?page=managesites&do=new )
it just works

So i wonder how relevant this error message is ? Because Mainwp child exist and is available from the mainwp main dashboard…

Must be another reason than "MainWP Child plugin not detected or could not be reached! "

I did this test with 3 different websites : api add-site showed this message and then from the MainWP web, adding was working.

postman screenshot

and if i try to add a already existing website in mainwp, the error is still the same.
and the docs says "Required Parameters:
@TODO " so i wonder if this feature is live already ? :slight_smile:

thanks

Hi @Info1,

Thanks for verifying that the /get-sites-by-url endpoint works.

Regarding the /add-site and /edit-site endpoints, handling requests is a bit different.

These two endpoints require parameters to be JSON encoded so the parameters can be used as with the other requests. In the help documentation, we have an example how to handle these requests programmatically:

However, if you want to do it from Postman or some other app that provides you a similar way to handle API requests, here is how you can do it:

In the Body section, go to the raw tab and enter body parameters in JSON encoded format:

Next, in the Headers section, along with default headers, make sure to create Content-Type header with the value
application/json; charset=utf-8 and x-api-key header that contains your consuer_key and consumer_secret in JSON encoded format:

Hit the Send button, and it should work for you:

2 Likes

Hello, thanks for the detailed explanations.

Unfortunately it does not work, neither with Postman or with Make.com

i triple checked your tutorials, and triple checked my keys (they work)

but i 'm always getting this error :

  • Status code

401

  • Data

{“ERROR”:“Incorrect or missing consumer key and/or secret. If the issue persists please reset your authentication details from the MainWP > Settings > REST API page, on your MainWP Dashboard site.”}

Hi @Info1,
Are you able to duplicate this problem with some other site?
Can you please open a helpdesk ticket so I can collect more info and check this further?

2 Likes

Yes i tried with multiple sites and it never worked with api, and always worked with the web panel.
i just sent a support ticket

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.