1

I have a Rest server running using the Services module which is setup to receive node and user requests. I have also created a new content type with the following fields:

enter image description here

I am able to add new instances of this content type using Poster (a Firefox plugin for creating http-post requests) using an http-post to my rest server with the following body (using application/json content-type):

{
  "title":"online submission",
  "type":"basic_content",
  "field_text":[
    {
      "value":"Some Text"
    }
  ]
}

I have tried many different variations of this json string (including make it all one line) and it never seems populate the text field. Could anyone shed any light on this? I am willing to use a different content-type if necessary.

1

Field values need to be surrounded by an array, which holds all the potentially multiple entries for the field, and yet another array which holds all of the potential translations for the field.

In PHP that looks something like this:

$node->field_text['und'][0]['value'] = 'Some Text';

I haven't tested it but I'd guess the JSON equivalent would be something like this:

"field_text":
{
  "und": 
  [
    { "value": "Some Text" }
  ]
}

That may need a bit of tweaking.

  • Okay thanks. I'll play around with this. Where does the "und" come from? – Mike2012 Feb 8 '12 at 18:24
  • 1
    Sorry I meant to say: it stands for "Undefined language". You can also access it through the constant LANGUAGE_NONE. – Clive Feb 8 '12 at 18:31
  • Okay sweet I think I'm starting to understand, thanks again! It worked! – Mike2012 Feb 8 '12 at 18:38

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.