How to create nested paragraphs items programmatically? Basically, i am programmatically generating a node. Those nodes have several anidated paragraphs like this:

-title parent
 -body parent
 -links parent
 -title child
   -body child
   -links child

-another parent
 ..etc..


I'm doing this with paragraphs, i have a parent paragraph that includes another.
At the time of generating the node i'm generating in a sufficient manner the parent paragraph with the following code:
('field_contenido_padre' is the field that contains the parent paragraph)

$paragraph = new ParagraphsItemEntity(
      array(
        'field_name' =&gt; 'field_contenido_padre',
        'bundle' =&gt; 'acordeon'));
$paragraph-&gt;is_new = TRUE;
$paragraph-&gt;setHostEntity('node', $parent);
$paragraph-&gt;field_titulo_acordeon[LANGUAGE_NONE][0]['value'] = $value["title"];
$paragraph-&gt;field_body[LANGUAGE_NONE][0]['value'] = "jajaja";

$ia = 0;
foreach ($value["items"] as $k =&gt; $item){
    $paragraph-&gt;field_link_archivo[LANGUAGE_NONE][$ia]['title'] = $item;
    $paragraph-&gt;field_link_archivo[LANGUAGE_NONE][$ia]['url'] = $value["items"][((int) $k + 1)];
}
$paragraph-&gt;save();


OK. this works.
Following further from here is my problem.
Now i would like to attach a child paragraph to this recently generated parent paragraph.
I've tried the following with no success:


first, generate the child paragraph
('field_acordeon_hijo' is the field in parent paragraph that contains the child)



$paragraph = new ParagraphsItemEntity(
    array(
      'field_name' =&gt; 'field_acordeon_hijo',
      'bundle' =&gt; 'acordeon-hijo'));
$paragraph-&gt;is_new = TRUE;
$paragraph-&gt;setHostEntity('paragraphs_item', $parent);
$paragraph-&gt;field_titulo_acordeon_hijo[LANGUAGE_NONE][0]['value'] ='TITULAko Hijo';
$paragraph-&gt;body[LANGUAGE_NONE][0]['value'] = 'jajaja';
$paragraph-&gt;save();




Now i try to save the recent child into the parent's container field:

 $entity = entity_load('paragraphs_item', array($parent-&gt;item_id));  
 $entity = reset($entity);  
 $entity-&gt;field_acordeon_hijo[LANGUAGE_NONE] = array(
     0 =&gt; array(
       'value' =&gt; $id_child,
       'safe_value' =&gt; $id_child,
       'format ' =&gt; NULL));   
 $entity-&gt;revision = TRUE;   
 $entity-&gt;save(FALSE);   



I get no errors, the parent paragraph is generated fine, but i don't see the children paragraphs :-/

I guess it's because I'm attaching the child to the parent, while maybe I must attach it to the node; but in that case, how to point the child to the parent?
After two days, finally, i got it working.
Step 3 is not necessary. My error was in step 2, where I wrote badly the bundle name :-(
so it was

new ParagraphsItemEntity(
    array(
      'field_name' =&gt; 'field_acordeon_hijo',
      'bundle' =&gt; 'acordeon_hijo'))


note the underscore in acordeon_hijo