Working with the latest Drupal Services 2.x module.

Introduction

Within Drupal, there is a very powerful module called the Services module that many websites have been using for quite some time. Because of this, many modules, and even my recent book Flash with Drupal, based a big portion of their dependency on the Services module. However, since version 2.x, there have been massive changes to this module ( for the better ) that have seemed to break or make irrelevant many modules and documentation that were based on the Services module prior to version 2.x

This tutorial will act as a link between those two versions, where I will explain the differences between the older versions of Services to the newest version so that one can still follow along with an outdated tutorial, and then make it behave the same as the previous versions of Services before 2.x.

Difference 1: Key Authentication

With the latest version of Services, the most massive change that I can recognize is the separation of the authentication capabilities with the previous versions. With versions prior to 2.x, you would simply need to install the Services module and you would then have the ability to authenticate your service requests using the API key that you would create. This functionality is now wrapped up in a separate module bundled with Services 2.x called the Key Authentication module. Because of this, the very first thing that someone needs to do is make sure that they enable this module in addition to the Services module.

This module then needs to be enabled within the Services Administrator found at Administer | Site Building | Settings, where you will simply select the Key Authentication within the Authentication module drop-down, and then press the Save Settings button when you have done that. You will then need to make sure that both the Use keys and Use sessid fields are checked.

There is also an added feature here, where you can link the authentication on a per field basis using the CCK field authentication. This is a new feature ( but an awesome feature ), so this should not pose as a stumbling block when following legacy tutorials.

Difference 2: API Key service configuration

Also, with the latest version of Services, there has been a big change in how the API Key controls which services can be utilized with that key. This is a great thing, but is another thing that has broken previous documentation and implementations. The API key is now able to specify which services it is able to control, and these will need to be enabled within the API Key configuration of the key you created with the older version of Services. For example, let's suppose that we created a new API Key called My API Key, within the settings of that key, you will now see a list of check boxes for each service. You will need to enable the services that you will be using. For most examples, this will entail the following services.

  • system.connect
  • node.get
  • views.get
  • user.get
  • vote.getVote
  • vote.getUserVote
  • vote.setVote
  • vote.deleteVote

Just remember, if you are using any other services, such as creating or deleting the nodes, you will need to enable those services ( node.save and node.delete respectively ) in the API Key that you are using in your application.

Difference 3: User Permissions

This is one change that I am pleased to see... Less permissions to configure between Services 2.x and the legacy Services module versions. In previous versions of Services, there were some user permissions that would need to be set in order to get views to work... These were load any node data and load own node data. I am pleased to say, that these are no longer necessary and you should not worry about setting the permissions for these non-existent permissions in the latest version of Services. The only permission that you will need to make sure is enabled still is the access services permission.

So, with that said, I hope that this puts everyone back on the right track when it comes to working through a legacy tutorial and apply that tutorial to the new Services 2.x module.

Sponsors