From Zero To Hero: Learning The TalentLMS REST API

The TalentLMS REST API: Basics, Use, And Further Readings

Software attacks fewer people per year than sharks do.

In fact, if my statistics are correct, software has never attacked anybody, ever.

And yet many people are afraid of the software on their home or work computer -- they seldom delve too much into its capabilities, they don’t try different customizations, and they convince themselves that they cannot handle anything more difficult than reading their email.

Against all of this fear, in this series of articles, we celebrate diving in and getting the most out of your software. Of course, the fact that we are writing about TalentLMS makes this much easier.

Thanks to TalentLMS’ Cloud-based nature, you are spared the worry about installation, setup, and maintenance. Plus, whatever you might do with it, you won’t get viruses of break your OS. And, of course, it is an LMS designed from the ground up with ease-of-use in mind.

So what are you waiting for? Let’s dive into TalentLMS’ REST API capabilities for this week’s installment.

You Need Some REST

Or rather, you need a REST API.

An API (short for Application Programming Interface) is a way for different a program to talk to another, and have the other program do some stuff for it or give it some information.

A REST API is just a particular way of creating APIs, one that is easy to get started with, that is supported by all major vendors, and that plays well with web technologies.

REST is, unarguably, the most popular web API style these days. TalentLMS of course not only follows it, but touts it as the main, official and documented, way of programmatically controlling your TalentLMS portal.

So, what can you do with TalentLMS’ REST API, and, more importantly, how should you go about using it? We’ll answer both of these questions in the following sections.

No REST For The Wicked

So, when would you need to leverage TalentLMS’ REST capabilities?

Well, a great opportunity would be whenever you have some other system that you need to hook up with your eLearning portal.

Sure, TalentLMS comes with loads of integration options (especially through its support for Zapier) -- but they still don’t cover every possible third-party program, and in most probability, they don’t support any in-house programs that your enterprise might have developed over the years. But REST does.

The beauty of REST, you see, is that it allows you or your IT team to easily create their own integration by connecting one system with another, in a Lego-like fashion.

In fact, and that’s another major use case for REST, you might not even have another system you want TalentLMS to talk to. REST is also great for automating TalentLMS itself with simple programming scripts that can be written in almost any language.

And while the current TalentLMS REST API sticks to the basics, as it gets expanded in future releases, you’ll be able to create and orchestrate even more advanced integrations and automations with your TalentLMS targeting REST scripts.

And The REST Is History

REST APIs are based on three basic things: A program (the client) that calls another program (the server), and a way to describe the commands and data that are exchanged between those two programs (serialization).

The client can be some third-party system that supports making REST calls or one of your own programs or scripts.

The server in our case is TalentLMS.

The serialization, or the way messages are exchanged between TalentLMS and your program, are simple HTTP, GET and POST queries and parameters on the client side, and a simple text-based (and human-readable) format called JSON on the TalentLMS side. JSON looks like this:

txt [
2      {"name": "John Smith", "age": 23},
3      {"name": "Jack Wick", "age": 22},
4      {"name": "Jane Doe", "age": 21}
5 ]

The fourth ingredient is where to send commands or ask for data. In REST, those are called "endpoints", and look just like this:

https://yourportal.talentlms.com/api/v1/courses

If they remind you of web addresses, it’s because they are web addresses. TalentLMS’ REST API re-uses the way we talk to web pages to have programs talk to one another. In fact, if not for TalentLMS’ REST API key protection, you could just paste that line in your web browser and get your results back.

Also, note how REST endpoints are pretty much self-describing. The one above, for example, returns a list of all your portal’s courses (/courses). The /api/v1 part is there just to tell you that you’re calling TalentLMS "API" and that it’s the first version "v1" of that particular endpoint’s implementation.

Using TalentLMS’ REST API

As we mentioned earlier, you can use the TalentLMS REST API from any programming language you like (or from any program and/or service that allows you to make REST calls). You just call into the provided API endpoints, a list of which you can find in the API documentation, like you would to any other REST system.

That said, TalentLMS has gone through the trouble of wrapping their REST API into a nice little PHP wrapper (helper script) that makes it even easier to use. Using it, a command to get all users, which in PHP would look like:

txt $curl = curl_init();
2 $opts = array();
3 $opts[CURLOPT_HTTPGET] = 1;
4 $opts[CURLOPT_URL] = "https://myportal.talent.com/api/v1/users";
5 $opts[CURLOPT_RETURNTRANSFER] = true;
6 $opts[CURLOPT_CONNECTTIMEOUT] = 30;
7 $opts[CURLOPT_TIMEOUT] = 80;
8 $opts[CURLOPT_RETURNTRANSFER] = true;
9 $opts[CURLOPT_USERPWD] = $MY_API_KEY.’:’;
10 $opts[CURLOPT_SSL_VERIFYPEER] = false;
11 $opts[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
12 curl_setopt_array($curl, $opts);
13 $response = json_decode(curl_exec($curl));
14 curl_close ($ch);

Becomes just:

txt $users = TalentLMS_User::all();

That said, the above is a contrived, "do everything by hand", PHP example. In most cases, the programmer would have used a helper library that would have reduced the number of lines to just 3 or 5 lines. But even so, you can’t beat the simple, one line ease-of-use that TalentLMS’ REST API PHP wrapper offers.

In any case, and whatever method you choose for using the TalentLMS’ REST API, there are over 50 endpoints that allow you to get information for all kinds of system entities (users, courses, lessons, etc.), set user status, create and delete courses, users, and groups, enroll users to courses or add them to courses and branches, get test and survey results, and more.

You will find them in the documentation and you can create example snippets for your favorite language using (REST API service) Postman as described in the Knowledge Base.

Note that, depending on your TalentLMS plan, there will be limits to how many API calls you can make per hour. That said, even the free tier allows for 50 API calls per hour -- which should be more than enough for the modest needs of small, free-tier portal instances.

Conclusion

In this article, we had a look at TalentLMS’ REST API, what it is, what you can do with it, how it looks, and how one can get started with using it. It’s a topic worth exploring, as it not only offers a lot of power for extending and integrating your TalentLMS portal to other systems, but it’s also a good, and approachable, starting point for getting one’s feet wet regarding programming. If you want to know more, beyond the extensive documentation we’ve already offered, make sure to read our recent blog post on the TalentLMS REST API and automation.

Stay tuned, for more articles with advanced TalentLMS related tips, tricks, and tutorials.

eBook Release: TalentLMS
TalentLMS
An award-winning LMS for those looking to build online courses for any purpose in a few easy clicks, even with zero experience.
Close