Support » Plugin: License Manager for WooCommerce » lmfwc_rest_cannot_view Error 401

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @codac

    Thank you for your message and for using my plugin. Sorry for the late reply, I was quite busy the last 2-3 months.

    Odd, have you tried with POSTMAN? Does it work there?

    codac

    (@codac)

    Thank god you replied, I’m quite desperate in finding a solution.
    In Postman, the following call works:

    https://www.my-url.com/wp-json/lmfwc/v2/licenses/validate/THE-PRETENDER?consumer_key={{consumer_key}}&consumer_secret={{consumer_secret}}

    Authorization is Basic Auth with Comsumer Key as Username und Consumer Secret as Password.

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @codac

    Did you make sure that this is a GET request? Perhaps you can also send me your POSTMAN collection and I’ll take a look myself.

    codac

    (@codac)

    This is my Code:

    //validate license key
    				$curl = curl_init();
    
    				curl_setopt_array($curl, array(
    					CURLOPT_URL => "https://www.my-url.com/wp-json/lmfwc/v2/licenses/validate/".$this->lcns."?consumer_key=".$this->lmfwcConsumerKey."&consumer_secret=".$this->lmfwcConsumerSecret,
    					CURLOPT_RETURNTRANSFER => true,
    					CURLOPT_ENCODING => "",
    					CURLOPT_MAXREDIRS => 10,
    					CURLOPT_TIMEOUT => 0,
    					CURLOPT_FOLLOWLOCATION => false,
    					CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    					CURLOPT_CUSTOMREQUEST => "GET",
    				));
    
    				$response = curl_exec($curl);
    				$err = curl_error($curl);
    
    				$result = json_decode($response, true);
    
    				curl_close($curl);

    So yes the call is defined to be a GET request.

    Where can I send you my Postman Collection to?

    • This reply was modified 1 month ago by codac.
    • This reply was modified 1 month ago by codac.
    • This reply was modified 1 month ago by codac.
    Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @codac

    I already got the link to the POSTMAN collection from your original post, good that you quickly edited it out.

    I was also able to do it via POSTMAN, I’ll try with a PHP script and let you know in a bit.

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @codac

    I managed to get it working by adding the User-Agent header.

    Try adding the following before the curl_exec() method:

    $headers = array(
    	'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'],
    );
    
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

    Please let me know if it worked for you as well.

    codac

    (@codac)

    That did the trick. The final code is:

    //validate license key
    				$curl = curl_init();
    
    				curl_setopt_array($curl, array(
    					CURLOPT_URL => "https://www.my-url.com/wp-json/lmfwc/v2/licenses/validate/".$this->lcns."?consumer_key=".$this->lmfwcConsumerKey."&consumer_secret=".$this->lmfwcConsumerSecret,
    					CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
                                            CURLOPT_RETURNTRANSFER => true,
    					CURLOPT_ENCODING => "",
    					CURLOPT_MAXREDIRS => 10,
    					CURLOPT_TIMEOUT => 0,
    					CURLOPT_FOLLOWLOCATION => false,
    					CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    					CURLOPT_CUSTOMREQUEST => "GET",
    				));
    
    				$response = curl_exec($curl);
    				$err = curl_error($curl);
    
    				$result = json_decode($response, true);
    
    				curl_close($curl);

    Can you explain why this part of code is necessary?

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @codac

    I honestly don’t know why this part is necessary. Do you maybe have a security plugin on your website which blocks all requests without a user agent?

    codac

    (@codac)

    Yes I do, so that might be it then…
    Thank you very much Drazen!

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @codac

    No problem!

    If you’re satisfied with the plugin and the support, I would like to ask you to write a plugin review here on WordPress.org. The reviews really help the plugin grow, and mean a lot to me personally.

    Here’s the link: https://wordpress.org/support/plugin/license-manager-for-woocommerce/reviews/#new-post

    Let me know if there is anything else I can do.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.