Posting children to a Structure This question is a follow up of a previous question see: (Entry Form - Multiple Entries &amp; Entry Type &amp; Parent)

I am trying to add multiple children to a pre-existing multi level structure:

Level 1
--Level 2 (The parent where I am adding the children)
----Child 1
----Child 2
..etc 


My Controller: 

public function actionSaveAnimals(){
$this-&gt;requirePostRequest();

if($rodentsData = craft()-&gt;request-&gt;getParam('rodent')){
  $rodentErrors = [];
  foreach ($rodentsData as $rodentData){
      if (array_key_exists('entryId', $rodentData) &amp;&amp; $rodentId = $rodentData['entryId']) {
          if (!$rodent = craft()-&gt;elements-&gt;getElementById($rodentId)) {
              throw new Exception('Could not find rodent with the given Id');
          }
      } else {
          $rodent = new EntryModel();
          $rodent-&gt;typeId = 6; // change your entryType Id here
          $rodent-&gt;sectionId = craft()-&gt;request-&gt;getParam('sectionId');
          $rodent-&gt;parentId = craft()-&gt;request-&gt;getParam('parentId');
          $rodent-&gt;authorId = craft()-&gt;request-&gt;getParam('authorId');
      }

      $rodent-&gt;getContent()-&gt;setAttributes($rodentData['fields']);

      if (!craft()-&gt;entries-&gt;saveEntry($rodent)) {
          $rodentErrors[] = $rodent-&gt;getErrors();
      }else{
          $rodentErrors = [];
      }
  }
  // include errors of each item
  craft()-&gt;urlManager-&gt;setRouteVariables(array(
      'rodentErrors' =&gt; $rodentErrors
  ));
}


}

And my form: 

&lt;form method="post" accept-charset="UTF-8"&gt;
{{ getCsrfInput() }}
{# your plugin name and function name #}
&lt;input type="hidden" name="action" value="experiment/SaveAnimals"&gt;
{# the id of your section for me its 4 you need to change this value to your section Id #}
&lt;input type="hidden" name="sectionId" value="4"&gt;
{# enable the entry #}
&lt;input type="hidden" name="enabled" value="1"&gt;
{# id of your entry leave it blank to insert a new entry, insert a id to change an existing entry#}
&lt;input type="hidden" name="entryId" value=""&gt;
&lt;input type="hidden" name="parentId" value="{{ entry.id }}"&gt;
&lt;input type="hidden" name="authorId" value="{{ currentUser.id }}"&gt;

&lt;div class="fields"&gt;
  &lt;div class="field mt3"&gt;
    &lt;label class="f5 lh-copy pb2" for="title"&gt;Amount of Animals&lt;/label&gt;
    {#&lt;input class="pa3 input-reset ba bw0 br2 w-100" type="number" id="Cage__Amount" placeholder="5" max="10" required&gt;#}
    &lt;input type="text" name="rodent[0][fields][title]" value="Add Identifier"&gt;
    &lt;input type="text" name="rodent[1][fields][title]" value="Add Identifier"&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class="field submit mv4"&gt;
  &lt;button class="bg-dark-blue white ph3 pv2 input-reset pointer ba bw0 f5 dib lh-copy w-100" type="submit"&gt;Create experiment&lt;/button&gt;
&lt;/div&gt;




I am currently getting this error: 

Trying to get property of non-object 

From EntriesService.php(468) 

if ($entry-&gt;getSection()-&gt;type != SectionType::Structure)


Any help much appreciated!
The section ID was incorrect - set correctly and this function works.