{"id":34640630,"url":"https://github.com/mainwp/mainwp-api-client-php","last_synced_at":"2026-05-23T20:34:06.807Z","repository":{"id":325493993,"uuid":"938120117","full_name":"mainwp/mainwp-api-client-php","owner":"mainwp","description":"A PHP wrapper for the MainWP REST API. Easily interact with the MainWP REST API securely using this library. If using a HTTPS connection this library uses BasicAuth, else it uses Bear Token to provide a secure connection to MainWP.","archived":false,"fork":false,"pushed_at":"2025-03-07T13:14:40.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-11-21T18:13:17.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mainwp.dev","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mainwp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-24T13:03:37.000Z","updated_at":"2025-05-30T11:27:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mainwp/mainwp-api-client-php","commit_stats":null,"previous_names":["mainwp/mainwp-api-client-php"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mainwp/mainwp-api-client-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainwp%2Fmainwp-api-client-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainwp%2Fmainwp-api-client-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainwp%2Fmainwp-api-client-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainwp%2Fmainwp-api-client-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mainwp","download_url":"https://codeload.github.com/mainwp/mainwp-api-client-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mainwp%2Fmainwp-api-client-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33412082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T18:09:33.147Z","status":"ssl_error","status_checked_at":"2026-05-23T18:09:31.380Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-24T17:16:48.973Z","updated_at":"2026-05-23T20:34:06.802Z","avatar_url":"https://github.com/mainwp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MainWP API Client PHP\n\nA PHP wrapper for the MainWP REST API. Easily interact with the MainWP REST API securely using this library. If using a HTTPS connection this library uses BasicAuth, else it uses Bear Token to provide a secure connection to MainWP.\n\n## Installation\n\nCreate composer.json as bellow if want to get package from github\n\n```\n{\n  \"repositories\": [\n      {\n          \"type\": \"vcs\",\n          \"url\": \"https://github.com/mainwp/mainwp-api-client-php.git\"\n      }\n  ],\n  \"require\": {\n      \"mainwp/mainwp-api-client-php\": \"dev-main\"\n  }\n}\n\n```\n\n```\ncomposer require mainwp/mainwp-api-client-php\n```\n\n## Getting started\n\nGenerate API credentials following this instructions [MainWP REST API](https://mainwp.com/kb/mainwp-rest-api/)\n.\n\nCheck out the MainWP API endpoints and data that can be manipulated in [MainWP REST API Endpoints](https://www.postman.com/mainwp/mainwp/collection/ujfddk4/mainwp-rest-api-v2-current).\n\n## Setup\n\nSetup for the new WP REST API integration (MainWP 5.2 or later):\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse MainWP\\Dashboard\\Client;\n\n$mainwp = new Client(\n  'http://example.com',\n  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',\n  [\n    'version' =\u003e 'v2',\n  ],\n);\n\nor\n\n$mainwp = new Client(\n  'http://example.com',\n  false,\n  [\n    'version' =\u003e 'v2',\n    'version' =\u003e 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',\n    'version' =\u003e 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',\n  ]\n);\n\n```\n\n## Client class\n\n```php\n$mainwp = new Client($url, $options, $consumer_apikey );\n\nor\n\n$options['consumer_key'] = $consumer_key;\n$options['consumer_secret'] = $consumer_secret;\n\n$mainwp = new Client($url, $options );\n\n```\n\n### Options\n\n| Option             | Type     | Required | Description                                        |\n| ------------------ | -------- | -------- | -------------------------------------------------- |\n| `url`              | `string` | yes      | Your Store URL, example: http://mydashboard.dev/   |\n| `consumer_apikey`  | `string` | no\t     | Your API consumer Bearer token key                 |\n| `options`          | `array`  | no       | Extra arguments (see client options table)         |\n\n#### Client options\n\n| Option                   | Type     | Required | Description                                                                                                                                            |\n| ------------------------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `version`                | `string` | no       | API version, default is `v2`                                                                                                                           |\n| `timeout`                | `int`    | no       | Request timeout, default is `15`                                                                                                                       |\n| `verify_ssl`             | `bool`   | no       | Verify SSL when connect, use this option as `false` when need to test with self-signed certificates, default is `true`                                 |\n| `auth_method`            | `string  | no       | Use Bearer Token `bearer` or Basic 'basic' auth for requests, default is `bearer`                                                      |                    |\n| `consumer_key`    \t     | `string` | no    \t | Your API consumer key                      \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  |\n| `consumer_secret` \t     | `string` | no   \t   | Your API consumer secret                   \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  |\n| `follow_redirects`       | `bool`   | no       | Allow the API call to follow redirects                                                                                                                 |\n| `query_string_auth`      | `bool`   | no       | Force Basic Authentication as query string when `true` and using under HTTPS, default is `false`                                                       |\n| `user_agent`             | `string` | no       | Custom user-agent, default is `MainWP API Client-PHP`                                                                                                  |\n| `method_override_header` | `bool`   | no       | If true will mask all non-GET/POST methods (PUT/DELETE/etc.) by using POST method with added `X-HTTP-Method-Override: METHOD` HTTP header into request |\n| `extension_api`          | `string` | no       | Use for MainWP's Extensions API                                                                                                             \t\t  |\n\n## Client methods\n\n### GET\n\n```php\n$mainwp-\u003eget($endpoint, $parameters = []);\n```\n\n### POST\n\n```php\n$mainwp-\u003epost($endpoint, $data);\n```\n\n### PUT\n\n```php\n$mainwp-\u003eput($endpoint, $data);\n```\n\n### DELETE\n\n```php\n$mainwp-\u003edelete($endpoint, $parameters = []);\n```\n\n### OPTIONS\n\n```php\n$mainwp-\u003eoptions($endpoint);\n```\n\n#### Arguments\n\n| Params       | Type     | Description                                                  |\n| ------------ | -------- | ------------------------------------------------------------ |\n| `endpoint`   | `string` | MainWP API endpoint, example: `sites` or `sites/sync/12` |\n| `data`       | `array`  | Only for POST and PUT, data that will be converted to JSON   |\n| `parameters` | `array`  | Only for GET and DELETE, request query string                |\n\n#### Response\n\nAll methods will return arrays on success or throwing `HttpClientException` errors on failure.\n\n```php\nuse MainWP\\Dashboard\\HttpClient\\HttpClientException;\n\ntry {\n  // Array of response results.\n  $results = $mainwp-\u003eget('sites');\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($results, true) . '\u003c/code\u003e\u003cpre\u003e'; // JSON output.\n  // Example: [ 'success' =\u003e 1, 'total' =\u003e 10, 'data' =\u003e [...]]\n  // Last request data.\n  $lastRequest = $mainwp-\u003ehttp-\u003egetRequest();\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($lastRequest-\u003egetUrl(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Requested URL (string).\n  echo '\u003cpre\u003e\u003ccode\u003e' .\n    print_r($lastRequest-\u003egetMethod(), true) .\n    '\u003c/code\u003e\u003cpre\u003e'; // Request method (string).\n  echo '\u003cpre\u003e\u003ccode\u003e' .\n    print_r($lastRequest-\u003egetParameters(), true) .\n    '\u003c/code\u003e\u003cpre\u003e'; // Request parameters (array).\n  echo '\u003cpre\u003e\u003ccode\u003e' .\n    print_r($lastRequest-\u003egetHeaders(), true) .\n    '\u003c/code\u003e\u003cpre\u003e'; // Request headers (array).\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($lastRequest-\u003egetBody(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Request body (JSON).\n\n  // Last response data.\n  $lastResponse = $mainwp-\u003ehttp-\u003egetResponse();\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($lastResponse-\u003egetCode(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Response code (int).\n  echo '\u003cpre\u003e\u003ccode\u003e' .\n    print_r($lastResponse-\u003egetHeaders(), true) .\n    '\u003c/code\u003e\u003cpre\u003e'; // Response headers (array).\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($lastResponse-\u003egetBody(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Response body (JSON).\n} catch (HttpClientException $e) {\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($e-\u003egetMessage(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Error message.\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($e-\u003egetRequest(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Last request data.\n  echo '\u003cpre\u003e\u003ccode\u003e' . print_r($e-\u003egetResponse(), true) . '\u003c/code\u003e\u003cpre\u003e'; // Last response data.\n}\n```\n\n## Release History\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmainwp%2Fmainwp-api-client-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmainwp%2Fmainwp-api-client-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmainwp%2Fmainwp-api-client-php/lists"}