# "Could not find a PSR-18 compatible HTTP client" in WordPress, PHP SDK

**URL:** <https://community.auth0.com/t/could-not-find-a-psr-18-compatible-http-client-in-wordpress-php-sdk/142059>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [August 28, 2024, 11:41pm UTC](https://community.auth0.com/t/could-not-find-a-psr-18-compatible-http-client-in-wordpress-php-sdk/142059 "2024-08-28T23:41:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leslye](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leslye/32/59495_2.png) [@leslye](https://community.auth0.com/u/leslye)\
**Post date:** [August 28, 2024, 11:41pm UTC](https://community.auth0.com/t/could-not-find-a-psr-18-compatible-http-client-in-wordpress-php-sdk/142059/1 "2024-08-28T23:41:34Z")

</div>

I’m getting the following error: “Could not find a PSR-18 compatible HTTP client. Please install one, or provide one using the `setHttpClient()` method.”

The code is trying to update the metadata in Auth0 after it’s updated in WordPress. Here is the code:

```auto
	use Auth0\SDK\Auth0;
	use Auth0\SDK\Configuration\SdkConfiguration;
	use Auth0\SDK\API\Authentication;
	use Auth0\SDK\API\Management;
	use Auth0\SDK\Utility\HttpResponse;
	use GuzzleHttp\Client;

function update_auth0_metadata_with_wp_roles($user_id) {
	
	
    // Get the WordPress user object
    $user = get_userdata($user_id);
    
    // Get the user's roles
    $roles = $user->roles;
    
    // Get the user's Auth0 user_id
    $all_meta_for_user = get_user_meta($user_id);
    
    $auth0_user_id = $all_meta_for_user['wp_auth0_id'][0];
    
    // If we don't have an Auth0 user_id, we can't update the metadata
    if (empty($auth0_user_id)) {
	    write_log(get_user_meta($user_id));
        return;
    }
        
    // Initialize the Auth0 SDK
    $auth0_domain = WP_Auth0_Options::Instance()->get('domain');
    $client_id = WP_Auth0_Options::Instance()->get('client_id');
    $client_secret = WP_Auth0_Options::Instance()->get('client_secret');
        
    $config = [
        'domain' => $auth0_domain,
        'clientId' => $client_id,
        'clientSecret' => $client_secret,
	'audience' => ['https://' . $auth0_domain .'/api/v2/'] ,
        'tokenAlgorithm' => 'RS256',
	'tokenEndpoint' => 'https://' . $auth0_domain . '/oauth/token',
        'debug' => true
       
    ];

    try {
        //$auth0 = new \Auth0\SDK\Auth0($config);
        $auth0 = new Auth0($config);
        
        // Get an access token
        $token = $auth0->getAccessToken();
        
        // Initialize the Management API client
        //$management = $auth0->management();
		
	// Set the headers for the Management API client
        $management->getHttpClient()->getConfig()->setHeaders([
            'Content-Type' => 'application/json',
            'Accept' => 'application/json'
        ]);
                
        // Update the user's metadata
        $management->users()->update($auth0_user_id, [
            'user_metadata' => ['wp_roles' => $roles]
        ]);
        
    } catch (Exception $e) {
        // Handle any errors
        error_log('Error updating Auth0 metadata: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
        error_log('Auth0 config: ' . print_r($config, true));

    }
}

// Hook our function to run when user roles are updated
add_action('set_user_role', 'update_auth0_metadata_with_wp_roles', 10, 1);
//add_action('add_user_role', 'update_auth0_metadata_with_wp_roles', 10, 1);
add_action('remove_user_role', 'update_auth0_metadata_with_wp_roles', 10, 1);

```

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [August 29, 2024, 8:07pm UTC](https://community.auth0.com/t/could-not-find-a-psr-18-compatible-http-client-in-wordpress-php-sdk/142059/2 "2024-08-29T20:07:18Z")

</div>

Hi @leslye

Welcome to the Auth0 Community!

I’m not a PHP expert, but found a similar topic with a user reporting the same error → [Problem with installation of auth0 - #3 by konrad.sopala](https://community.auth0.com/t/problem-with-installation-of-auth0/107264/3)

The error was raised because not all files were uploaded to the server. Can you check for that?

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![leslye](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leslye/32/59495_2.png) [@leslye](https://community.auth0.com/u/leslye)\
**Post date:** [August 29, 2024, 10:24pm UTC](https://community.auth0.com/t/could-not-find-a-psr-18-compatible-http-client-in-wordpress-php-sdk/142059/3 "2024-08-29T22:24:07Z")

</div>

I used Composer to install everything. Both auth0 and guzzle seem to be all installed correctly.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 12, 2024, 10:24pm UTC](https://community.auth0.com/t/could-not-find-a-psr-18-compatible-http-client-in-wordpress-php-sdk/142059/4 "2024-09-12T22:24:45Z")

</div>

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