• Resolved redhat894

    (@redhat894)


    The plugin is great, we like it.
    When we do some updating via api, we’ve got problem, and by following the related resolved issue:
    https://wordpress.org/support/topic/post-avatar-using-rest-api/
    we can fetch the media info of the avatar, but still we cannot update it by a post request /wp/v2/users/<id> including the media_id in post data.

    Our wordpress version: 6.0.2
    Plugin version: 2.6.0

    Thanks

    • This topic was modified 1 year, 10 months ago by redhat894.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Faisal Alvi

    (@faisal03)

    @redhat894 thank you for reaching out.

    I have tested and by sending media_id value in the simple_local_avatar object, I was able to update the Avatar image. Can you please share how you are sending the request?

    • This reply was modified 1 year, 10 months ago by Faisal Alvi.
    Thread Starter redhat894

    (@redhat894)

    @faisal03 I got this, I didn’t wrap the media_id in simple_local_avatar before, now it’s working.
    Thanks.

    Hello @faisal03 ,

    So a sample rest api call to post by sending media_id value in the simple_local_avatar. will look like? Because I believe a sample code will go a long way to assist other users who need this like myself.

    great plugin by the way.

    Plugin Contributor Faisal Alvi

    (@faisal03)

    @msowah the following is the sample request call in PHP, sending a media_id value in the simple_local_avatar.

    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://mysite.local/wp-json/wp/v2/users/1/',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS =>'{
        "simple_local_avatar": {
            "media_id": 9218
        }
    }',
      CURLOPT_HTTPHEADER => array(
        'Authorization: Basic YWFais46bzlAvlVdCBrdVlnIGxPRTAgOG1ycCBiMzBzIFJYSEg=',
        'Content-Type: application/json',
        'Cookie: woocommerce_multicurrency_forced_currency=INR; woocommerce_multicurrency_language=en'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cannot update the avatar via REST api’ is closed to new replies.