Having trouble accessing arguments from my custom Resource

ldpm's picture

Hi, I'm new to creating Resources, and I'm having difficulty accessing the raw body from the POST. That body contains JSON that looks like this:


“documents” : [ {
           “vendor”: “ABC”,
    “guid” : “1423700E-7600-4184-A795-BBD17A7969B1”,
    “schema” : {
        “location” : “http://host.com/org/schema/CA/101”,
        “country code” : “CA”,
“version” : “101” }
    “entity” : [ { “name” : “Afilias Canada Corp.” } ],
“date last checked” : “2014-01-01”
“date last updated” : “2014-01-01”,
“permit validation” : true,
“fields” : [
    { “key” : “parent company”, “value” : [ “Afilias Limited” ] },
{ “key” : “street 1”, “value”: [ “4141 Yonge Street” ] },
},
{
    “guid” : “adfads-345143”,
    “schema” : {
        “location” : “http://host.com/org/schema/101”,
        “country code” : “CA”,
“version” : “101” }
    “entity” : [ { “name” : “Toronto Star” } ],
“date last checked” : “2014-01-03”
“date last updated” : “2014-01-01”,
“permit validation” : false,
“fields” : [
{ “key” : “street 1”, “value”: [ “1 Yonge Street” ] },
} ]
    }

It should be simple enough to decode in my handler, but I can't seem to access it even as a string. My mocule is here:

<?php
function uploader_resource_services_resources() {
  return array(
   
'uploader' => array(
     
'retrieve' => array(
       
'access callback' => '_uploader_resource_access',
       
'access arguments' => array('view'),
       
'access arguments append' => FALSE,
       
'callback' => '_uploader_resource_retrieve',

      ),
     
'create' => array(
       
'help' => 'handles the CREATE method of the uploader service',
       
'callback' => '_uploader_resource_create',
       
'access callback' => '_uploader_resource_access',
       
'access arguments' => array('view'),
       
'access arguments append' => FALSE,
       
'args' => array(
          array(
           
'name' => 'documents',
           
'type' => 'string',
           
'description' => 'upload JSON payload',
           
'source' => 'data',
           
'optional' => FALSE,
          ),
        ),
      ),
    ),
  );
}

function
_uploader_resource_create($documents) {
  return
"Hello, world!" . $documents;
}

function
_uploader_resource_retrieve($id) {
  return
"Retrieve " . $id;
}

function
_uploader_resource_access($op) {
  return
TRUE;
}
?>

In the CREATE handler, I'm just trying to show the contents of the POST right now, and I can't get that far. I'd expect it to return "Hello, World" plus the JSON string, but instead it just returns "Hello, World". What am I doing wrong? Thanks,

-Larry

Comments

Turns out it was just bad

ldpm's picture

Turns out it was just bad JSON data. Sorry!

Philadelphia Area

Group organizers

Group categories

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: