0

I have a have setup a custom endpoint via services and a REST server the custom end point looks like this,

https://website.local/api/v1/druaplsquare

The custom endpoint is built using the following code,

drupalsqaure.module

function drupalsquare_services_resources() {
  $resources = array();
  $resources['drupalsquare'] = array(
    'operations' => array(
         'create' => array(
             'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/drupalsquare'),
             'callback' => '_job_resource_create',
             'args' => array(
                 array(
                     'name' => 'node',
                     'optional' => FALSE,
                     'source' => 'data',
                     'description' => 'The node data to create',
                     'type' => 'array',
                 ),
             ),
             'access callback' => '_drupalsquare_resource_access'
         ),
         'delete' => array(
             'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/drupalsquare'),
             'callback' => '_job_resource_delete',
             'args' => array(
                 array(
                     'name' => 'jobref',
                     'optional' => FALSE,
                     'source' => array('path' => 0),
                     'description' => 'The job reference to delete',
                     'type' => 'string',
                 ),
             ),
             'access callback' => '_drupalsquare_resource_access'
         ),
    ),
  );
  return $resources;
}

resources/drupalsquare.inc

<?php

function _drupalsquare_resource_access() {
    return TRUE;
}

//function _drupalsquare_resource_retrieve($uid) {
//  $account = user_load($uid);
//
//  if (isset($account->data['checked_in'])) {
//      return array(
//          'uid' => $account->uid,
//          'name' => $account->name,
//          'last_checkin' => $account->data['checked_in'],
//      );
//  }
//  else {
//      return FALSE;
//  }
//}

function _drupalsquare_resource_checkin($JobReference, $date = NULL) {
    die(print_r($JobReference));
//  $account = user_load($uid);
//  $account->data['checked_in'] = is_null($date) ? REQUEST_TIME : $date;
//  user_save($account);
    return TRUE;
}

function _job_resource_create() {
    die("create");
}

function _job_resource_delete($jobref) {
    die("here");
}

I am making a cURL request this is endpoint, but I am first of all authenticating a user, and getting a token, I am then sending this token in the request header, however the endpoint above is returning,

Access denied for user anonymous

Can anyone see any reason as why this would be happening?

  • Have you checked Services modules permissions? – Ismail Cherri Sep 9 '18 at 21:53
  • Authenticated user can do all the actions they should be able to do. – Udders Sep 9 '18 at 23:40
0

In your code
Replace 'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/drupalsquare'),
with 'file' => array('type' => 'inc', 'module' => 'NAME_OF_YOUR_MODULE', 'name' => 'resources/drupalsquare'), It seems you're wrongly defining your INC file.

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.