• Resolved ulieckardt

    (@ulieckardt)


    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

    //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

    (@codename065)

    Add the following rule in your .htaccess file:

    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    Thread Starter ulieckardt

    (@ulieckardt)

    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 //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

    (@ulieckardt)

    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 2 years, 5 months ago by ulieckardt.
    • This reply was modified 2 years, 5 months ago by ulieckardt.
    Plugin Author Shahjada

    (@codename065)

    please add curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); with your php curl option setup

    Thread Starter ulieckardt

    (@ulieckardt)

    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

    (@ulieckardt)

    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.