I am integrating an API into my Wordpress website and I am having trouble understanding the instructions on Github as to how to install the API. I am comfortable with using Wordpress themes and plugins but I am new to coding + API.

I have downloaded the library from Github and extracted it on my computer. Where should I be saving this folder in my Wordpress directory, ie. root, plugins, themes or elsewhere?

It has asked for me to "Extract the library into the php include path." Is this the same as the extraction I have done above?

Then it requires me to integrate this line of code:

require_once(dirname(__FILE__) . 'path_to ChargeBee.php');

and I have no idea where I should do this. Do I need to create a separate .php file for this? I saw a video online where I could insert this in .htaccess. Is this correct? Or should I be placing it in one of the files of the library?

I assume "path_to Chargebee.php" above needs to be changed to the path where I save the library in my Wordpress directory?

The linkt to where the above information is is: https://github.com/chargebee/chargebee-php.

Any help would be appreciated to this newbie.:) Thanks in advance.

P/S: I thought I should add this. I spent the entire day yesterday looking at youtube API videos but none of them explained the basics for a dummy like me. I have tried searching Google but again I couldn't find anything answering my questions. I hope someone can help....pretty pleeeaasssee.....


this line IS your php inlcude path:

require_once(dirname(__FILE__) . 'path_to ChargeBee.php');

you need to change it to something specific to your coding. ie: are you putting this into a theme or a plugin? ( would suggest a plugin)

If that were the case you would use something like this:

require_once( CHARGEBEEPLUGIN_DIR . '/lib/chargebee.php' );

this would include the file that it finds at wp-content/plugins/chargebeeapi/lib/chargebee.php

the chargbee.php is what you're getting from github.

Do you have experience with api's though? It's not as simple as just putting the github folder on your system and you're off to the races unfortunately.

The link you referenced is the library to for the chargbee api. You now need to create your side of the tool to utilize the library. I suggested a plugin as that is how I do it. You're not going to just put it in the plugin folder though: you need to create a folder within the plugin directory with your new plugin folders.

for instance: In the wp-content/plugins folder you create a new folder, "chargebeeapi"

then in that folder you add your library (the lib folder you downloaded from gitub)


now in the chargbeeapi folder you create your main plugin php file that will reference the library by using the above include path.

In this php file you'll need to create form and submission button (this will vary depending upon how you need to interact with chargbee.) As well as a response container to get the response back after your request/push to their system. Lastly you'll need to tell wordpress this is a plugin and identify where the form / interaction will occur in wordpress.

  • Oooohhh! I see what you mean now. Does that mean I have to copy the entire contents of the chargebee-php folder to that Wordpress directory or just the Chargebee.pho file? And where do I place that line of code that requires the directory? Is there a reason why you would recommend having it in a plugin rather than a plugin directory? – lightpurpple Apr 11 '17 at 4:19
  • I added more information to my answer. – rudtek Apr 11 '17 at 5:39
  • Omg! It is so much involved than I thought it would be. I was hoping it would be a matter of copying the Chargebee folder to Wordpress and voila! It will take me forever to learn how to do all those things. Would you be interested in taking on installation of the API for me, paid for of course? I have had so much trouble finding someone who would do this for me? Everyone I have spoken to just wants to install the existing Chargebee plugin which broke my site when I tried it. – lightpurpple Apr 11 '17 at 6:10
  • you might be able to find my site in my profile... – rudtek Apr 11 '17 at 6:30
  • I tried using the contact form on your site but it is bringing up a failed to send message for some reason. – lightpurpple Apr 11 '17 at 7:42

An API is just a piece of code, that does nothing by itself. First thing to do is to figure out what is it that you want to do with that API, then write a plugin that wraps the API code and exposes API in the "wordpress way" via widgets, shortcodes, or in case it is a self contained JS file, enqueues it and set whatever are the required parameters (and add whatever admin is needed).

Where do you put the "API" code itself (the proper term in this case is more likely SDK) is of not much importance, it just obviously have to be part of the plugin, and to keep things clean you will probably want to keep it in its own directory.

This goes also for integrating it in a theme.

  • I didn't receive notification of this for some reason. This is so belated but thank you so much for your response. I decided to ditch API and put it in my 'too hard' basket. – lightpurpple Jul 2 '19 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.