Answers.Body: <p>As per your comments, the title field is required and causing a validation error. This can be resolved simply by setting the title.</p>
  
  <pre><code>$entry-&gt;title = 'The Title';
  </code></pre>
  
  <p>You can output the validation errors to be notified of any issues with saving the entries as follows.</p>
  
  <pre><code>if ($result === false) {
      \Craft:dd($entry-&gt;getErrors());
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-13T22:16:09.427Z
Answers.LastActivityDate: 2018-11-13T22:16:09.427Z
Answers.UserDisplayName: Ben Croker
Body: <p>I try to finish a plugin which imports data into my craftcms project. I already created a console based method/service, which I trigger/run in my shell. Inside my method(s) I receive data <code>(XML or JSON)</code> I parse my data and try to create and fill an entry of a specific channel I already created.</p>
  
  <p>I tried <code>"saveElement()"</code> which doesn't work.</p>
  
  <p>I found some tuts and informations for craftcms v2 (for example: <a href="https://docs.craftcms.com/api/v2/craft-entriesservice.html#public-methods" rel="nofollow noreferrer">https://docs.craftcms.com/api/v2/craft-entriesservice.html#public-methods</a>)</p>
  
  <p>Now i am stuck and i can not find any informations on how to solve this with craftcms v3.</p>
  
  <p>Here is my last version of code after hours of different trys :(</p>
  
  <pre><code>$section = Craft::$app-&gt;sections-&gt;getSectionByHandle('testentry');
  $entryTypes = $section-&gt;getEntryTypes();
  $entryType = $entryTypes[0];
  // Save Entry
  //$entry = new EntryModel();
  $entry = new \craft\elements\Entry();
  $entry-&gt;sectionId = $section-&gt;id;
  $entry-&gt;typeId = $entryType-&gt;id;
  //$entry-&gt;locale = Craft::$app-&gt;i18n-&gt;getPrimarySiteLocaleId();
  //$entry-&gt;authorId = 1;  // TODO:  Set author
  $entry-&gt;enabled = true;
  $entry-&gt;postDate = $post['post_date'];
  $entry-&gt;slug = $post['post_name'];
  //      $entry-&gt;getContent()-&gt;title = $post['post_title'];
  //      $entry-&gt;setContentFromPost(array(
  //          'body' =&gt; $postContent,
  //          'categoryCareer' =&gt; NULL,
  //      ));
  
  if (Craft::$app-&gt;elements-&gt;saveElement($entry)) {
      $result = true;
  } 
  else {
      echo 'Could not save the Job entry.'."\n";
      $result = false;
  }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-12T20:35:40.080Z
Comments.Text: This looks mostly correct but there is likely a validation issue with your entry, required fields for example. Does outputting `$entry->getErrors()` reveal anything?
Comments.UserDisplayName: Ben Croker
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-13T17:36:50.600Z
Comments.Text: Oh no, i am so damn stupid.
  You are right, the last structure should work, but i did not display any errors anymore..... the title is required.
  
  So after i saw the error i was able to import several entries.
  Thanks a lot !!
Comments.UserDisplayName: Thomas
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-13T17:44:46.537Z
Comments.Text: Now i am able to continue, have to find out how to import and store images with an entry and that's it
Comments.UserDisplayName: Thomas
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-13T22:16:35.553Z
Comments.Text: Glad to hear it, I've added this as an answer so that you can mark it as solved.
Comments.UserDisplayName: Ben Croker
Tags: <plugin-development><entries><plugins><import>
Title: Craft 3 plugin to import channel entries
ThreadText: # Craft 3 plugin to import channel entries
  
  (Asked by: username_0 on 2018-11-12)
  
  I try to finish a plugin which imports data into my craftcms project. I already created a console based method/service, which I trigger/run in my shell. Inside my method(s) I receive data `(XML or JSON)` I parse my data and try to create and fill an entry of a specific channel I already created.
  
  I tried `"saveElement()"` which doesn't work.
  
  I found some tuts and informations for craftcms v2 (for example: <https://docs.craftcms.com/api/v2/craft-entriesservice.html#public-methods>)
  
  Now i am stuck and i can not find any informations on how to solve this with craftcms v3.
  
  Here is my last version of code after hours of different trys :(
  
  ```
  $section = Craft::$app->sections->getSectionByHandle('testentry');
  $entryTypes = $section->getEntryTypes();
  $entryType = $entryTypes[0];
  // Save Entry
  //$entry = new EntryModel();
  $entry = new \craft\elements\Entry();
  $entry->sectionId = $section->id;
  $entry->typeId = $entryType->id;
  //$entry->locale = Craft::$app->i18n->getPrimarySiteLocaleId();
  //$entry->authorId = 1;  // TODO:  Set author
  $entry->enabled = true;
  $entry->postDate = $post['post_date'];
  $entry->slug = $post['post_name'];
  //      $entry->getContent()->title = $post['post_title'];
  //      $entry->setContentFromPost(array(
  //          'body' => $postContent,
  //          'categoryCareer' => NULL,
  //      ));
  
  if (Craft::$app->elements->saveElement($entry)) {
      $result = true;
  } 
  else {
      echo 'Could not save the Job entry.'."\n";
      $result = false;
  }
  
  ```
  
  **Tags:** plugin-development, entries, plugins, import
  
  > **Comments:**
  > **username_1**: This looks mostly correct but there is likely a validation issue with your entry, required fields for example. Does outputting `$entry->getErrors()` reveal anything?  
  > **username_0**: Oh no, i am so damn stupid. You are right, the last structure should work, but i did not display any errors anymore..... the title is required.  So after i saw the error i was able to import several entries. Thanks a lot !!  
  > **username_0**: Now i am able to continue, have to find out how to import and store images with an entry and that's it  
  > **username_1**: Glad to hear it, I've added this as an answer so that you can mark it as solved.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-13. Score: 0 | Accepted answer
  
  As per your comments, the title field is required and causing a validation error. This can be resolved simply by setting the title.
  
  ```
  $entry->title = 'The Title';
  
  ```
  
  You can output the validation errors to be notified of any issues with saving the entries as follows.
  
  ```
  if ($result === false) {
      \Craft:dd($entry->getErrors());
  }
  
  ```
  
  
  ---
  
  