0

I am trying to submit a node via an android native app in java. I am using services 3.3, and I am able to login, and submit to a Content type assuming all of the fields are Text fields.

But I would also like to add some taxonomy terms as fields. The Tax term is already defined on the drupal system. I have a term NAME: "A". tid:37.

what is the services technique to submit a Tax term? or even some hints.

I also want to submit some images as well... another question perhaps

  • You need to create a custom service for this that is quite easy. You can look a simple example over here drupal.org/node/2166921. If required I can share some more example with you. – Pushpinder Rana May 26 '14 at 8:34
0

I'm not familiar with Services module or drupal's web service (I usually use Symfony for such Services), but I don't think there are any specific rules for such task. Assuming there is a callback in your module which receives a data from external resource, e.g.:

function module_menu()
{
  ...

  $items['my-path/%'] = array(
    'title' => 'TITLE',
    'page callback' => 'myCallback', // this can be either `drupal_get_form` or your callback function..
    'page arguments' => array(1),
    ...
  );

  ...
}

and define that callback:

function myCallback($data /* assuming $data is an array, but It can be another type, JSON, XML... */)
{
  if(empty($data)) {
    // some dummy check
    return 'Invalid data';
  }

  $node = entity_get_controller('node');
  $node->type = 'MY_TYPE';
  // set other base fields such as author...

  $nodeWrapper = entity_metadata_wrapper('node', $node);

  $nodeWrapper->field_MYTEXTFIELD->set($data['text_field_data']);
  $nodeWrapper->field_TERMFIELD->set($data['term_field_data']);
  ....
  $nodeWrapper->save();

  ...

  // finally return response
}
0

I am assuming that since you already have the TID, you wish to create a note with an association to that TID.

If you have a node with a field called "tags", then you must do the following:

Within the JSON you send to the node creation endpoint (endpoint/node), you must include a JSONObject with a key of "field_tags". The value paired to that key should be a JSONArray named as per your language requirement (und, in many cases). This JSONArray should be populated with JSONObjects keyed by "tid".

Overall, this should be the structure of your JSONObject (Notice that the square brackets indicate a JSONArray):

"field_tags": { "und": [ { "tid": "37" } ] }

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.