I am using services module recently i have noticed that i am getting all responses along with [NULL] at the end. So my app dev team is unable to parse the JSON.

What i am doing wrong ? What may be the possible causes for this ?

I think it happens with my custom module only. But i am sure i am using drupal_json_output with sufficient parameters.

I have posted this question a few weeks ago, but my app dev tem fixed it. Now i am facing it again. Any help ?

 * Implementation of hook_services_resources().
function noteresource_services_resources() {
  return array(
    'gymcam' => array(
      'actions' => array(
        'sendmail' => array(
          'help' => 'Send gymcam to admin',
          'callback' => 'gymcam_sendemail',
          'access callback' => 'gymcam_resource_access',
          'access arguments' => array('sendmail'),
          'access arguments append' => TRUE,
          'args' => array(
              'name' => 'uid',
              'type' => 'int',
              'description' => 'The uid of the logged in user',
              'source' => 'data',
              'optional' => TRUE,

function gymcam_sendemail($data) {
  $data = array('status' => 'error', 'msg' => 'Mail not sent');

I dont know why do you need to convert the data to JSON format. My idea is that you just return an array. The returned data of your custom service will be based on how we call it.

function gymcam_sendemail($data) {
  $data = array('status' => 'error', 'msg' => 'Mail not sent');
  return $data;

If you want to use JSON for returned data, just call /gymcam/sendmail.json

  • Thats working. I am unaware that i dont need to convert to json. Thank you.
    – niksmac
    Jun 7 '13 at 2:26
  • This was really a simple answer, @NikhilM you need more concentration.
    – druplicon
    Jul 29 '13 at 16:42
  • @druplicon thanks though, my mistake.
    – niksmac
    Jul 30 '13 at 2:19

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.