No "body" when creating a node programatically, with Internationalization I am trying to create event type nodes in Drupal 7, using data from an external database.
It's reading correctly, and creating a node almost perfectly.
But, it doesn't seem to save the "body" part of the node.

db_set_active('default');

foreach ($results as $record) { // Results gained from an ext DB
  echo 'Creating event: ' . $record-&gt;name;

  $node = new stdClass();
  $node-&gt;type = 'event';
  node_object_prepare($node);

  $node-&gt;title    = $record-&gt;name;
  $node-&gt;language = "en";;

  $node-&gt;body[$node-&gt;language][0]['value']   = $record-&gt;bodytext;  /* This line ?? */

  $path = 'content/programmatically_created_node_' . date('YmdHis');
  $node-&gt;path = array('alias' =&gt; $path);

  node_save($node);  
}


This is early stages, and I have a number of fields to put into events type nodes, including some custom fields.

I am unsure how to map the fields in the external database to node fields.  The line above might be completely wrong at this stage, but it's gone though many many failing iterations.

As requested: DPM output of the node (after save)

... (Object) stdClass
type (String, 5 characters ) event
uid (String, 2 characters ) 10
status (Integer) 1
promote (Integer) 0
sticky (Integer) 0
created (Integer) 1357635638
revision (Boolean) FALSE
comment (String, 1 characters ) 1
language (String, 3 characters ) und
menu (Array, 13 elements)
title (String, 42 characters ) Starter Course
field_pakp_p1_id (String, 36 characters ) 78ee9b05-9225-fb5b-9bbb-508eada6ba81
body (Array, 1 element)
  en (Array, 1 element)
    0 (Array, 3 elements)
      value (String, 19 characters ) This is a body text
      summary (String, 19 characters ) Here goes a summary
      format (String, 13 characters ) filtered_html
path (Array, 1 element)
validated (Boolean) TRUE
changed (Integer) 1357635638
timestamp (Integer) 1357635638
publish_on (Integer) 0
unpublish_on (Integer) 0
log (String, 0 characters )
nid (String, 3 characters ) 423
tnid (Integer) 0
translate (Integer) 0
vid (String, 3 characters ) 423
field_event_status (Array, 1 element)
xmlsitemap (Array, 15 elements)


...

I also tried using the drupal_form_submit method..

foreach ($results as $record) { // Results gained from an ext DB
    echo 'Creating event: ' . $record-&gt;name;
    $node = (object) array(
      'type' =&gt; 'event',
      'language' =&gt; LANGUAGE_NONE
    );
    node_object_prepare($node);

    $form_state = array();  
    $form_state['values']['language'] = "en";
    $form_state['values']['title'] = $record-&gt;name;  
    $form_state['values']['description']['value'] = "description....";
    $form_state['values']['body']['value'] = "body....";
    $form_state['values']['body']['format'] = filter_default_format();
    $form_state['values']['body']['LANGUAGE'] = "en";
    $form_state['values']['name'] = $user-&gt;name;  
    $form_state['values']['op'] = t('Save');

    drupal_form_submit("{$node-&gt;type}_node_form", $form_state, $node);

}


But again, try as I might, using this method I could not get the "body" to be saved.  (I know there is some junk in this code, it's my experimentation.)

Questions.


Which is the best method to use for my application.  node_save or drupal_form_submit
For the correct method, which is the best way to store the body text?
How do I know what are valid $form_state array keys, or $node elements, so I can find the correct place for further field mapping?
If your site is multi-lingual then 'en' would contain the English-language translations of your original node (I think that's right).

Going out on a limb, I'd say you're not running a multilingual site and instead want to use the LANGUAGE_NONE constant, e.g.

$node-&gt;language = LANGUAGE_NONE;


If your site isn't multi-lingual, using 'en' would probably explain why you're not seeing the body value saved. It might even be there in the database, but because the field system is looking for fields with a LANGUAGE_NONE when it's attaching data to a language-neutral node, nothing gets found.

That might be a load of nonsense though ;)