Title: REST API &#8211; authentication does not work
Last modified: June 12, 2022

---

# REST API – authentication does not work

 *  Resolved [ulieckardt](https://wordpress.org/support/users/ulieckardt/)
 * (@ulieckardt)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/)
 * I’d like to use the API but I can not authorize.
 * I use the manual from here:
    [https://imsas.github.io/wpdm-rest-api-docs/#authentication](https://imsas.github.io/wpdm-rest-api-docs/#authentication)
 * //No matter which of the methods I use, I always get the same error
 *     ```
       $authorization =  'Authorization: Basic {base64("xxxx:yyyyyyy")';
       //$authorization = 'Authorization: Bearer KEY_CREATED_IN_WPDM_API_PUGIN'; 
   
       $url = "https://xxxxx.com/wp-json/wpdm/v1/packages/";
       $curl = curl_init();
       curl_setopt($curl, CURLOPT_URL, $url);
       curl_setopt($curl, CURLOPT_HTTPHEADER, $authorization );
       curl_setopt($curl, CURLOPT_HTTPHEADER, "Content-Type: application/json" );
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       $resp = curl_exec($curl);
       curl_close($curl);
       var_dump($j_result);
   
       Result = {"code":"rest_forbidden","message":"You cannot view the post resource.","data":{"status":401}}"
       ```
   
 * Does the API really work or where is my mistake?
 * Thank you for your help
 * Uli

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Shahjada](https://wordpress.org/support/users/codename065/)
 * (@codename065)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15729808)
 * Add the following rule in your .htaccess file:
 *     ```
       RewriteEngine On
       RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
       ```
   
 *  Thread Starter [ulieckardt](https://wordpress.org/support/users/ulieckardt/)
 * (@ulieckardt)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15729862)
 * Thank you for the fast reply. now I get the result.
 * I have another question:
 * If I want to update a package with the url
    [https://xxxxx.de/wp-json/wpdm/v1/packages/4070](https://xxxxx.de/wp-json/wpdm/v1/packages/4070)//
   I got the package ID by the request before, I get the result “code”:”rest_no_route”,…
   404
 * What can I do?
 * Thanks
 * Uli
 *  Thread Starter [ulieckardt](https://wordpress.org/support/users/ulieckardt/)
 * (@ulieckardt)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15729863)
 *     ```
       Thank you for the fast reply. now I get the result.
   
       I have another question:
   
       If I want to update a package with the url
       https://MY_DOMAIN/wp-json/wpdm/v1/packages/4070 
       //I got the package ID by the request before,
   
       I get the result “code”:”rest_no_route”, … 404
   
       What can I do?
   
       Thanks
   
       Uli
       ```
   
    -  This reply was modified 3 years, 11 months ago by [ulieckardt](https://wordpress.org/support/users/ulieckardt/).
    -  This reply was modified 3 years, 11 months ago by [ulieckardt](https://wordpress.org/support/users/ulieckardt/).
 *  Plugin Author [Shahjada](https://wordpress.org/support/users/codename065/)
 * (@codename065)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15730021)
 * please add `curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");` with your php curl
   option setup
 *  Thread Starter [ulieckardt](https://wordpress.org/support/users/ulieckardt/)
 * (@ulieckardt)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15730255)
 * Hi,
    perfect, it works 🙂
 * But how can I change the data of a package?
 * I’ve tried:
 * $post[‘password’] = “[123]”;
    $jsonData = json_encode($post); curl_setopt($curl,
   CURLOPT_POSTFIELDS, $jsonData);
 * —
    And I’ve tried $data = <<<DATA { “password”: “The Alchemist” } DATA;` curl_setopt(
   $curl, CURLOPT_POSTFIELDS, $data);
 * —
    and $messageData = ‘{ “title”: “The Alchemist” }’; curl_setopt($curl, CURLOPT_POSTFIELDS,
   $messageData);
 *     ```
       $curl = curl_init($url);
               curl_setopt($curl, CURLOPT_URL, $url);
               curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
               $headers = array(
                   "Accept: application/json",
                   "Authorization: Basic 1234567890",
               );
               curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
   
               curl_setopt($curl, CURLOPT_USERAGENT, 'Mautic');
               curl_setopt($curl, CURLOPT_POSTFIELDS, $messageData); 
               curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
   
              curl_setopt($curl, CURLOPT_POST, 1);
       ```
   
 * But no update 🙁
 * The result shows me the none-update data. What can I do?
 * Thank you.
 * Uli
 *  Thread Starter [ulieckardt](https://wordpress.org/support/users/ulieckardt/)
 * (@ulieckardt)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15731356)
 * SOLVED 🙂
 * $data = array(‘password’=>’123’);
    $data_json = json_encode($data); $headers 
   = array( “Content-Type: application/json; charset=utf-8”, “Content-Length: ” .
   strlen($data_json), “Authorization: Basic asadasdasdasdasd”, );
 * $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url); curl_setopt(
   $curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CUSTOMREQUEST,“
   PUT”); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POSTFIELDS,
   $data_json); $resp = curl_exec($curl); curl_close($curl);`

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘REST API – authentication does not work’ is closed to new replies.

 * ![](https://ps.w.org/download-manager/assets/icon-256x256.png?rev=1561688)
 * [Download Manager](https://wordpress.org/plugins/download-manager/)
 * [Support Threads](https://wordpress.org/support/plugin/download-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/download-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/download-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/download-manager/reviews/)

## Tags

 * [wpdm](https://wordpress.org/support/topic-tag/wpdm/)

 * 6 replies
 * 2 participants
 * Last reply from: [ulieckardt](https://wordpress.org/support/users/ulieckardt/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/rest-api-authentication-does-not-work/#post-15731356)
 * Status: resolved