I want to add website automatically in Main Wp Plugin by using php or any api can anyone guide me -
Advance thanks!
I want to add website automatically in Main Wp Plugin by using php or any api can anyone guide me -
Advance thanks!
Hi Maleet,
thanks for reaching out.
Since version 4.1.3, MainWP allows you to use REST API calls to do this.
Here you can find the full REST API documentation: REST API - MainWP Developer
For adding sites, you can use the following Endpoint:
URI:
/add-site
Method:
POST
Example Request:
$url = 'https://yourdomain.com/wp-json/mainwp/v1/site/child-site-add';
$body = array(
'consumer_key' => 'xxxxxxxxxxxxx',
'consumer_secret' => 'yyyyyyyyyyyyyy',
'name' => 'child site',
'url' => 'http://childsite.com',
'admin' => 'Adminname',
);
$body = wp_json_encode( $body );
$headers = array();
$headers['Content-Type'] = 'application/json; charset=utf-8';
$resp = wp_remote_post(
$url,
array(
'method' => 'POST',
'timeout' => 45,
'headers' => $headers,
'body' => $body,
)
);
I am getting some error, during try that API, Can you help me
{“code”:“rest_no_route”,“message”:“No route was found matching the URL and request method.”,“data”:{“status”:404}}
Hi Malkeet,
thanks for getting back to me.
Looks like the request URL is not correct.
Can you please try with:
https://example.com/wp-json/mainwp/v1/site/add-site
thanks Bogdan, its working now for me
Thanks for letting me know. I am happy to see that.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.