Open htv-longdt opened 1 year ago
That error does not seem to be coming from this library. Could you please post here what your connection setup looks like ? Make sure to redact sensitive variables,
Hi, Here is the code
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use WPRestClient\Auth\BasicAuth;
use WPRestClient\Core\ApiClient;
use WPRestClient\Core\RepositoryRegistry;
use WPRestClient\Repository\PagesRepository;
use WPRestClient\Entity\PageEntity;
# create an instance of our http client
$httpClient = new Client();
$auth = new BasicAuth('admin', 'op9a y88i 1wEE 322o kQeO JM4g');
$apiClient = new ApiClient('https://test.local', null, $auth);
# via the auth setter
$apiClient->setAuth($auth);
# create a new page called `Hobbies` // Working fine
// $apiClient->sendRequest( 'post', '/pages', [ 'title' => 'Hobbies', 'status' => 'publish' ] );
# delete a page called `Hobbies` // Cause fatal error
$apiClient->sendRequest( 'delete', '/pages', [
'id' => 38419
]
);
I used the code above and can add a new page. But got error when delete page.
Notice: Trying to get property 'message' of non-object in /home/longdt/Works/hattatsu/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php on line 44
Notice: Trying to get property 'data' of non-object in /home/longdt/Works/hattatsu/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php on line 44
Notice: Trying to get property 'status' of non-object in /home/longdt/Works/hattatsu/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php on line 44
Fatal error: Uncaught Error: Wrong parameters for WPRestClient\Core\ApiResponseException([string $message [, long $code [, Throwable $previous = NULL]]]) in /home/longdt/Works/test/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php:19 Stack trace: #0 /home/longdt/Works/test/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php(19): Exception->__construct(NULL, NULL, Object(GuzzleHttp\Exception\ClientException)) #1 /home/longdt/Works/test/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php(44): WPRestClient\Core\ApiResponseException->__construct(NULL, NULL, Object(GuzzleHttp\Exception\ClientException)) #2 /home/longdt/Works/test/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiClient.php(110): WPRestClient\Core\ApiResponseException::fromClientException(Object(GuzzleHttp\Exception\ClientException)) #3 /home/longdt/Works/test/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ in /home/longdt/Works/test/app/public/rest-api/vendor/angelxmoreno/wprestclient/src/Core/ApiResponseException.php on line 19
Can you have a tutorial to add, edit, delete user via API? Thanks so much!
Hi We have just followed this quick start: https://wprestclient.readthedocs.io/en/latest/quickstart/ but got this error: Fatal error: Uncaught Error: Call to a member function fetch() on string in /home/app/public/rest-api/rest-api.php:31 Stack trace: #0 {main} thrown in /home/app/public/rest-api/rest-api.php on line 31 Is this quick start is working fine now. We are using PHP version 8.0.22 Thanks so much!