0
votes

I am using PHP and able to fetch information from an API. I am new to Drupal and I would like to know how the data fetched from an external API can be stored inside a Drupal database. I have created the nodes through the Drupal interface and this has created the corresponding tables in the database. What would be the best approach for this implementation?

Thank you

1

1 Answers

0
votes

The easiest solution would probably be to use Feeds.

Feeds is the alpha/dev stages for Drupal 8 but it should be useable as more than 3000 installs have been reported (at the time of writing).

Feeds allows you to map an external api to specific fields in your content type and save them as local nodes. It can also be configured to fetch data at intervals or one off.

For a more custom solution you should create a custom module that fetches the API data and save them as fields in a content type sort of like this

use \Drupal\node\Entity\Node;

$node = Node::create([
  'type'        => 'article',
  'title'       => 'Article test',
  ///...
]);
$node->save();