Is there a way that I can force a node to be unpublished by using the node resource?

Requirement: Site A defines a content type 'item' which is published by default. Site B needs to create 'item' nodes on A, and these auto-created nodes should be unpublished.

function toolreq_test_create() {
$toolreq_endpoint = variable_get("toolreq_endpoint", "");
$options = toolreq_service_login();
if (!is_array($options)) {
    print "error<p>";
//create a node

$node_data = array(
                      "title"=>"DHC Tool 04 dev",
                      //"status"=> FALSE, //ensure unpublished
                      "status" => 0,
                      "language" => "und", //lanugage neutral

//use json
$options['headers']['content-type'] = "application/json";
$options['method'] = 'POST';
$options['data'] = json_encode($node_data);
$request = drupal_http_request($toolreq_endpoint . '/node', $options);

Since the node table's status field is the mysql INT type (with a default of 1), I would think that I could pass status=>0 in the above code, but doing that results in a published node. I have tried passing 0 using both JSON and x-www-form-urlencoded data.

If I use status=>FALSE and use JSON, the node is created as unpublished, but I think that this is equivalent to inserting '' in the node.status field which results in a mysql warning:

mysql> INSERT INTO `bamboodirt`.`node` (`nid`, `vid`, `type`, `language`, `title`, `uid`,
`status`, `created`, `changed`, `comment`, `promote`, `sticky`, `tnid`, `translate`) 
VALUES (NULL, 21, 'item', 'und', 'sql insert test', '0', '', '0', '0', '0', '0', '0', '0', 
Query OK, 1 row affected, 1 warning (0.03 sec)

| Level   | Code | Message                                                  |
| Warning | 1366 | Incorrect integer value: '' for column 'status' at row 1 |

I would live with that warning, but my webhost's mysql is less permissive and I get a real error (durning node_save() I think) on that server:

"SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'status' at row 1"

(Here's the thread over at Pantheon http://help.getpantheon.com/pantheon/topics/json_node_create_works_on_localstack_fails_with_error_500_on_pantheon.)

Is there a way that I can force a node to be unpublished by using the node resource, or do I need to write my own resource?

1 Answer 1


Try setting the 'status' field to TRUE or FALSE instead of 0 or 1.

  • Using FALSE works as noted above. I think the FALSE/NULL value for status gets converted to 0 by MySQL. Common.inc L6833: // Type cast to proper datatype, except when the value is NULL and the // column allows this. // // MySQL PDO silently casts e.g. FALSE and '' to 0 when inserting the value // into an integer column, but PostgreSQL PDO does not. Also type cast NULL // when the column does not allow this.
    – Brian Wood
    Jan 3, 2012 at 21: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.