Title: API wrap around
Last modified: October 11, 2019

---

# API wrap around

 *  Resolved [kimherrero](https://wordpress.org/support/users/kimherrero/)
 * (@kimherrero)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/api-wrap-around/)
 * Hi to all, considering that my software has an InstallId that needs to get paired
   with the LicenseId and that I want to avoid to hard code the consumer keys, I
   made the following work around php that calls the rest API and does the extra
   job.
 * As I am not a php expert, the question is, is it ok to make a call inside a call,
   or it could be a potentially server overloading problem?
 * By the way, congrats for this excellent solution.
 * P.D. I echo the results because I treat them as an INI file.
 * Kim
 * —————
 * <?php
 * if(isset($_GET[“id”])) {
 *  $iguid = $_GET[“id”];
    $ch = curl_init();
 *  curl_setopt_array($ch, array(
    CURLOPT_URL => “{host}/wp-json/lmfwc/v2/licenses/”.
   $iguid.”?consumer_key={consumer_key}&consumer_secret={consumer_secret}”, 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($ch);
    $err = curl_error($ch);
 *  curl_close($ch);
 *  if ($err) {
    echo “Error #:” . $err; } else {
 *  $json = json_decode($response);
    if ( $json->success == true) {
 *  echo “Key=” . $json->data->licenseKey . “\n”;
    echo “Order=” . $json->data->
   orderId . “\n”; echo “Version=” . $json->data->productId . “\n”; echo “Status
   =” . $json->data->status . “\n”; echo “Expires=” . $json->data->expiresAt . “\
   n”;
 *  }
 *  // extra job here
 *  }
 * }
 * ?>

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

 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12021827)
 * Hello [@kimherrero](https://wordpress.org/support/users/kimherrero/),
 * thank you for your message and for using my plugin.
 * I have a question first: Is `$iguid` your license key? If so, all is good.
 * It is always best to cut down on remote API calls as much as possible. You said
   that you don’t want to hardcode the `consumer_key` and `consumer_secret`, and
   that is reasonable. However, your “order” is wrong in your example. You would
   first need to do your extra job to obtain the consumer_key and consumer_secret,
   and then replace the placeholders on this line:
 * `CURLOPT_URL => “{host}/wp-json/lmfwc/v2/licenses/”.$iguid.”?consumer_key={consumer_key}&
   consumer_secret={consumer_secret}”`
 * I’m referring to `{consumer_key}` and `{consumer_secret}`. And it shouldn’t cause
   an overload by itself. However you will have to make 2 API calls to get the job
   done, which increases the risk of something going wrong. The request will also
   take longer to complete. But if you absolutely cannot have your keys hardcoded,
   then I don’t see another way.
 * Let me know if you need further assistance
 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12047889)
 * Hello [@kimherrero](https://wordpress.org/support/users/kimherrero/),
 * have you been able to work this one out? Do you need any more assistance?
 *  [pipermp3](https://wordpress.org/support/users/pipermp3/)
 * (@pipermp3)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12221317)
 * Tried the codesnippet provided above, but getting syntax problems all over the
   place.
 * Are there any specific php modules that needs installed for it?
 * I blank copied the code – adjusted the URL to match a postman-working URL (to
   make sure it worked) but im throwing php parse problems from line 26 and further.
 * If I entirely remove `if ($err) {` and the rest, its 200,- working fine.
 * Issues begins right at that point, and when I fix one line, I break another.
   
   Any chance someone can look it over?
 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12221358)
 * Hello [@pipermp3](https://wordpress.org/support/users/pipermp3/),
 * Try this:
 *     ```
       <?php
   
       if (isset($_GET["id"])) {
   
       	$iguid = $_GET["id"];
       	$ch    = curl_init();
   
       	/**
       	 * Replace {host} with your website URL
       	 * Replace {consumer_key} with your consumer key generated by the plugin (starts with ck_)
       	 * Replace {consumer_secret} with your consumer secret generated by the plugin (starts with cs_)
       	 */
       	curl_setopt_array($ch, array(
       	CURLOPT_URL => "{host}/wp-json/lmfwc/v2/licenses/". $iguid ."?consumer_key={consumer_key}&consumer_secret={consumer_secret}",
       	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($ch);
       	$err = curl_error($ch);
   
       	curl_close($ch);
   
       	if ($err) {
       		echo "Error #:" . $err;
       	} else {
       		$json = json_decode($response);
   
       		if ( $json->success == true) {
       			echo "Key=" . $json->data->licenseKey . "\n";
       			echo "Order=" . $json->data->orderId . "\n";
       			echo "Version=" . $json->data->productId . "\n";
       			echo "Status=" . $json->data->status . "\n";
       			echo "Expires=" . $json->data->expiresAt . "\n";
       		}
   
       		// extra job here
       	}
   
       }
   
       ?>
       ```
   
 *  [pipermp3](https://wordpress.org/support/users/pipermp3/)
 * (@pipermp3)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12221411)
 * Hi [@drazenbebic](https://wordpress.org/support/users/drazenbebic/)
 * Whoah, that was hella quick response.
 * Yep, in this setup that snippet works 100%.
    Done a few translations for you 
   for Norwegian whilst I was waiting for ya.
 * Great plugin by the way, works fab. Newbie to API in general so this plugin has
   proven quite good in getting to grips of it.
 * For anyone else that eventually lands on this code snippet, it works if you have
   a “form” that submits TO this code.
 * Ie, the code above would be your api.php
    and this could be your “form”;
 * form.php
    <html> <body>
 * <form action=”[http://hostaddress/api.php&#8221](http://hostaddress/api.php&#8221);
   method=”get”; _<—- api.php is the codesnippet above_
    License Key: </br> <input
   type=”text” name=”id”> </br> <input type=”submit”> </form>
 * </body>
    </html>
 * Horribly basic form, no validation.
    But it works, and is a great starter-point
   to develop on further what you may aim to do with the API/Plugin.
 * Thanks again [@drazenbebic](https://wordpress.org/support/users/drazenbebic/)!
    -  This reply was modified 6 years, 4 months ago by [pipermp3](https://wordpress.org/support/users/pipermp3/).
 *  [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * (@drazenbebic)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12222079)
 * [@pipermp3](https://wordpress.org/support/users/pipermp3/)
 * No problem, also thanks a lot for the translations! 🙂
 * If you hit another snag or need help with anything else, do not hesitate to ask.
 * PS: I would greatly appreciate if you could take some time out of your day to
   write a plugin review here on WordPress.org. These 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](https://wordpress.org/support/plugin/license-manager-for-woocommerce/reviews/#new-post)

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

The topic ‘API wrap around’ 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/)
 * [order](https://wordpress.org/support/topic-tag/order/)
 * [products](https://wordpress.org/support/topic-tag/products/)
 * [serial](https://wordpress.org/support/topic-tag/serial/)
 * [serial key](https://wordpress.org/support/topic-tag/serial-key/)

 * 6 replies
 * 2 participants
 * Last reply from: [Drazen Bebic](https://wordpress.org/support/users/drazenbebic/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/api-wrap-around/#post-12222079)
 * Status: resolved