Title: Python REST API Example
Last modified: February 1, 2020

---

# Python REST API Example

 *  Resolved [blastframe](https://wordpress.org/support/users/blastframe/)
 * (@blastframe)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/python-rest-api-example/)
 * Hello,
    Similar to [this user’s request](https://wordpress.org/support/topic/it-is-possible-to-get-some-example/),
   I was hoping to find an example of your plugin using Python so a user can authenticate
   my software on their computer (unless there’s a safer way to do this). I’m not
   sure which address to get or how to find if a license is valid. I looked for 
   docs [here](https://www.licensemanager.at/docs/rest-api/v2/) and [here](https://www.licensemanager.at/docs/tutorials-how-to/additional-rest-api-validation/),
   but didn’t see any. I am using Python’s [Requests](https://requests.readthedocs.io/en/master/user/authentication/)
   library.
 *     ```
       import requests
   
       def main():
           r = requests.get('https://api.github.com/user', auth=('username', 'password'))
           print r.status_code
           print r.headers['content-type']
           print r.encoding
           print r.text
           print r.json()
   
       if __name__=='__main__':
           main()
       ```
   
 * Thank you!
    -  This topic was modified 6 years, 3 months ago by [blastframe](https://wordpress.org/support/users/blastframe/).

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

 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-12401300)
 * Hello [@blastframe](https://wordpress.org/support/users/blastframe/)
 * Thank you for your message and for using my plugin.
 * I’m sorry for the late reply. I honestly don’t have any Python knowledge myself,
   so i can’t help with this. However, if you were to create a Python library which
   helps utilize the REST API, I will add it to my website (with proper credit of
   course):
 * [https://www.licensemanager.at/docs/rest-api/libraries/](https://www.licensemanager.at/docs/rest-api/libraries/)
 * I am currently looking for people willing to share their own libraries, and Python
   definitely is on the list.
 *  Thread Starter [blastframe](https://wordpress.org/support/users/blastframe/)
 * (@blastframe)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-12402873)
 * Hi,
    I would be happy to share if I develop such a library. Could you please 
   direct me to a simple GET request in any language (PHP perhaps?) and I will do
   my best to replicate it in Python?
 * I’m not sure what the REST URL would be for my site with your plugin installed.
 * Thank you!
 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-12403240)
 * [@blastframe](https://wordpress.org/support/users/blastframe/)
 * Take a look at the REST API docs here: [https://www.licensemanager.at/docs/rest-api/](https://www.licensemanager.at/docs/rest-api/)
 * An example request URL would be:
 * (GET) [http://www.example.com/wp-json/lmfwc/v2/licenses](http://www.example.com/wp-json/lmfwc/v2/licenses)
 * This would list all the licenses from the database. If you need anything else
   let me know.
 *  Thread Starter [blastframe](https://wordpress.org/support/users/blastframe/)
 * (@blastframe)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-12403560)
 * That’s excellent, I’ll give it a try! If I get it working I’ll post the Python
   code. Thank you, Drazen.
 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-12403641)
 * [@blastframe](https://wordpress.org/support/users/blastframe/)
 * Awesome, thanks! I’m sure it will be a tremendous help to others 🙂
 * Once you’re done, you can send the library to [support@licensemanager.at](https://wordpress.org/support/topic/python-rest-api-example/support@licensemanager.at?output_format=md).
 * PS: To give you proper credit on my website I will also need your full name (
   or nickname, whatever you’re more comfortable with) + your website to which to
   link to.
 *  [processzip](https://wordpress.org/support/users/processzip/)
 * (@processzip)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13111318)
 * Hi everyone,
 * If you want to validate a key using this tool in Python, use the following method.
 * import requests
 *     ```
       def verify_account_key(account_key_to_check):
   
           yourwebsite = "" #for example, niftynicktools.com
           consumer_key = "" #the consumer_key given to you when you establish your API with License Manager
           consumer_secret = "" #the consumer_secret given to you when you establish your API with License Manager
           url = "https://" + yourwebsite + "/wp-json/lmfwc/v2/licenses/validate/" + account_key_to_check + "?consumer_key=" + \
                 consumer_key + "&consumer_secret=" + consumer_secret
   
           verification_json = requests.get(url, headers={"User-Agent": "XY"}).json()
   
           try:
               if verification_json['success'] == True:
                   return True
           except:
               return False
   
       #Try some keys
       verify_account_key("")
       verify_account_key("")
       ```
   
    -  This reply was modified 5 years, 10 months ago by [processzip](https://wordpress.org/support/users/processzip/).
 *  [mikeramsey869](https://wordpress.org/support/users/mikeramsey869/)
 * (@mikeramsey869)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13628552)
 * Nice snippet [@processzip](https://wordpress.org/support/users/processzip/) I
   wish i had seen that before i made my wrapper lol.
 * I added your snippet with attribution in my pylicensemanager which is opensource.
 * The the code has an option to generate uuid and to send that back in json response
   too. We just need the plugin to accept this by default and consider it valid 
   on the validate or activate vs invalid if its activating/validating on the same
   uuid vs failing saying already registered.
 * feel free to submit pull requests
    [https://gitlab.com/mikeramsey/pylicensemanager](https://gitlab.com/mikeramsey/pylicensemanager)
   [https://pypi.org/project/pylicensemanager/](https://pypi.org/project/pylicensemanager/)
 * [@drazenbebic](https://wordpress.org/support/users/drazenbebic/) Where do i put
   the filters and hooks for this?
    [https://www.licensemanager.at/docs/tutorials-how-to/additional-rest-api-validation/](https://www.licensemanager.at/docs/tutorials-how-to/additional-rest-api-validation/)
   [https://www.licensemanager.at/docs/tutorials-how-to/modifying-the-rest-api-response/](https://www.licensemanager.at/docs/tutorials-how-to/modifying-the-rest-api-response/)
 * Also is there any documentation for the upcoming v3 api? If so please let me 
   know would like to update the library to fully support all methods and would 
   be nice if we can add public key signed messages which can be verified client
   side to confirm the response is coming from our url and signed by our public 
   key.
 *  [willwinter](https://wordpress.org/support/users/willwinter/)
 * (@willwinter)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13630783)
 * Ive tried to setup the plugin and use the python requests script with the API
   but none of it seems to be working and i keep getting ‘There has been a critical
   error with your website’ when i manually use the links that im requesting using
   the API.
 * [https://i.snipboard.io/5wcNZS.jpg](https://i.snipboard.io/5wcNZS.jpg)
 *  [mikeramsey869](https://wordpress.org/support/users/mikeramsey869/)
 * (@mikeramsey869)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13632690)
 * can you provide the the scripts you use with the api keys removed and example
   to shown. If the wordpress is showing a 500 error its possible the PHP is wrong
   though vs the api.
 * Did you add stuff into your child theme’s functions.php? If so first off your
   going to want to probably comment out or remove it and make sure the wordpress
   is not showing errors when curling the domain api.
 * Heres minimal example Python script. You can load in like Pycharm and run easily
   to test retrieving a single license key.
 * This should work assuming you have created a License Key and setup your rest 
   API keys and their active and valid.
 * Edit the edit section with your information as applicable then run it
    [https://pastebin.com/pihY7Ry4](https://pastebin.com/pihY7Ry4)
 * Should look something like the below when valid key is run.
 * > [View post on imgur.com](https://imgur.com/a/kNC04LT)
 * Once you have confirmed the API is working then I recommend going back and trying
   to work with the fancy filters. I got hung up on trying to make it all work before
   gradually working up to what I wanted.
 * Only thing really left is getting it to save the uuid and nice_name from the 
   device into the license meta. The Validate does not check if expired inactive
   so best option I found was to validate based off the license key full details
   from the retrieve license details base and add my logic from there.
 * Hopefully that helps you [@willwinter](https://wordpress.org/support/users/willwinter/)
 *  [willwinter](https://wordpress.org/support/users/willwinter/)
 * (@willwinter)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13632833)
 * [@mikeramsey869](https://wordpress.org/support/users/mikeramsey869/) I was using
   the script above mentioned by [@processzip](https://wordpress.org/support/users/processzip/)
   but ive also just tried yours and for some reason im getting the same result 
   with the ‘critical error’ message, all ive done is install my theme and customise
   it and its necessary plugins, installed the license manager plugin, and created
   a testkey and some API credentials but it doesnt want to work, ive also tried
   changing the theme and disabling other plugins to see if there is some conflict
   but it still doesnt want to work, the only thing ive done is edit the wp-config
   to add define(‘LMFWC_PLUGIN_SECRET’, ‘secret.txt’); and define(‘LMFWC_PLUGIN_SECRET’,‘
   defuse.txt’); aswell as a few lines to turn on debugging to see if i can see 
   what is going wrong but that didnt work either. Im not having much luck with 
   this plugin unfortunately, im going to keep trying to fix it but if you can give
   any help that would be great. am i right in how i setup the plugin; fresh install
   of wordpress, installed my theme, installed license manager, created a key, created
   api keys and then im trying to run your script using my creds and website. theres
   no further setting up with permalinks or anything else that needs configuring?
 *  [willwinter](https://wordpress.org/support/users/willwinter/)
 * (@willwinter)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13632911)
 * I then get emails through of a critical error/technical issue such as this: [https://i.snipboard.io/QYRf6B.jpg](https://i.snipboard.io/QYRf6B.jpg)
 *  [willwinter](https://wordpress.org/support/users/willwinter/)
 * (@willwinter)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13633136)
 * Ive spoken to EasyWP support and let them see about the issue they had some technicians
   at it for an hour and resulted in this: [https://i.snipboard.io/67tBfu.jpg](https://i.snipboard.io/67tBfu.jpg)

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

The topic ‘Python REST API Example’ is closed to new replies.

 * ![](https://ps.w.org/license-manager-for-woocommerce/assets/icon-256x256.gif?
   rev=2824216)
 * [License Manager for WooCommerce](https://wordpress.org/plugins/license-manager-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/license-manager-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/license-manager-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/license-manager-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/license-manager-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/license-manager-for-woocommerce/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [python](https://wordpress.org/support/topic-tag/python/)
 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * 12 replies
 * 5 participants
 * Last reply from: [willwinter](https://wordpress.org/support/users/willwinter/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/python-rest-api-example/#post-13633136)
 * Status: resolved