How to create a node programatically with drupal_form_submit()?
The advantage of this method over node_save is that if you have field validation done by modules like field_validation or your own custom validations that you have previously implemented, the node saving will fail if the data sent does not comply with those validations.

global $user;
module_load_include('inc', 'node', 'node.pages');

$node = (object) array(
  'uid' =&gt; $user-&gt;uid,
  'name' =&gt; $user-&gt;name,
  'type' =&gt; 'MYCONTENTTYPE',
  'language' =&gt; LANGUAGE_NONE,
);
node_object_prepare($node);

// Get default values from attached fields.
$fields = field_info_instances('node');
$form_state = array();
foreach($fields['MYCONTENTTYPE'] as $field_name =&gt; $values) {
  $form_state['values'][$field_name] = array(LANGUAGE_NONE =&gt; array());
}

// Add the $form_state field values.
$form_state['values']['title'] = 'my title';
$form_state['values']['body'][LANGUAGE_NONE][0] = array(
  'value' =&gt; 'my body',
  'format' =&gt; 'full_html',
);
$form_state['values']['field_MYFIELD'][LANGUAGE_NONE][0]['value'] = 'blah blah';

// Without this line, not quite sure why, it wont work.
$form_state['values']['op'] = t('Save');

drupal_form_submit('MYCONTENTTYPE_node_form', $form_state, $node);

// Tell watch dog if any of the fields fail validation.
$errors = form_get_errors();
if (!empty($errors)) {
  foreach ($errors as $field_name =&gt; $message) {
    watchdog('MYMODULE', '%field: %message', array('%message'=&gt; $message, '%field' =&gt; $field_name));
  }
}