0

I'm using RESTws and POSTing a JSON object to "/node". Everything works fine until I include a List text field (checkbox type). The field in question is:

...
"field_days_closed_v": ["Monday", "Tuesday"],
...

When I post I get this error:

Recoverable fatal error: Argument 2 passed to RestWSBaseFormat::getResourceReferenceValue() must be of the type array, string given, called in .../restws/restws.formats.inc on line 278 and defined in RestWSBaseFormat->getResourceReferenceValue() line 311

My JSON is:

{
  "body": {
    "format": "filtered_html",
    "summary": "",
    "value": "test"
  },
  "field_opening_times_t": {
    "format": "filtered_html",
    "value": "Daily"
  },
  "field_price_category": "",
  "field_price_text_t": {
    "format": "filtered_html",
    "value": "<p>Free entry</p>"
  },
  "title": "Mark test test test",
  "type": "primary_article"
}

The field is a List(text) and the widget type is Check boxes/radio buttons. Values are:

Monday|Monday
Tuesday|Tuesday
Wednesday|Wednesday
Thursday|Thursday
Friday|Friday
Saturday|Saturday
Sunday|Sunday

Am I right in thinking it is just an array that should be POSTed?

Any ideas?

1
  • I don't see field_days_closed_v in your JSON format!. Where is it? and I'm pretty sure that the JSON format in my answer works for the field type you mentioned. So try to send the exact JSON format (by ignoring other fields) and see. Dec 16, 2014 at 10:56

1 Answer 1

1

The JSON format for list (text) for checkbox type would looks like follows

{"title":"My Day","type":"page","field_days_closed_v":{"und":["sunday", "monday"]}}

I've tested this, and working fine.

Here field_days_closed_v is the machine name of the List text field (checkbox type). similarly sunday, monday are the values of checkbox type so change them accordingly.

Hope this helps. :)

13
  • 1
    @MarkRobson Sorry for the delay. Can you post your complete JSON format here. It seems issue with other fields Dec 15, 2014 at 11:54
  • 1
    @MarkRobson Does it works fine without "£"? Have you checked that? Dec 19, 2014 at 12:38
  • 1
    @MarkRobson Have a look at this post - How to escape special characters in building a JSON string? Dec 19, 2014 at 12:54
  • 1
    @MarkRobson I use POSTER Add-on for Firefox to send json format to rest service. I didn't have time to check your scenario. I'll try to do that today. :) Dec 22, 2014 at 9:32
  • 1
    @MarkRobson I was busy yesterday. Just checked your scenario. It's working fine, even I add £ ot JSON format. If that doesn't work for you try something like "field_text":{"und":[{"value":"\u00a3"}]} for pound symbol. Dec 23, 2014 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.