What is the correct way to send a node list to the REST API? In Drupal, we can create nodes with the core module "RESTful Web Services". There is a lot of documentation about creating one node with one request, the Drupal documentation provides the following example:

curl --include \
  --request POST \
  --user klausi:secret \
  --header 'Content-type: application/hal+json' \
  --header 'X-CSRF-Token: &lt;obtained from http://example.com/rest/session/token&gt;' \
  http://example.com/entity/node?_format=hal_json \
  --data-binary '{"_links":{"type":{"href":"http://example.com/rest/type/node/article"}},"title":[{"value":"Example node title"}],"type":[{"target_id":"article"}]}'


We want to import 25.000 nodes on a regular basis and worry that this could take really long if we use a separate request for each node.

It should be possible to send a list of nodes. Drupal's REST web service uses the Serializer Component from the Symphony framework. The Symphony docs say that it includes the serialization of lists of nodes. Passing a list to the REST web service should simply look like this.

curl --include \
  --request POST \
  --user klausi:secret \
  --header 'Content-type: application/hal+json' \
  --header 'X-CSRF-Token: &lt;obtained from http://example.com/rest/session/token&gt;' \
  http://example.com/entity/node?_format=hal_json \
  --data-binary '[{"title":[{"value":"Title 1"}],"type":[{"target_id":"article"}]},{"title":[{"value":"Title 2"}],"type":[{"target_id":"article"}]}]'


When I send this data, I get this response.


  Could not determine entity type bundle: type field is missing.


t seems that the serializer does not recognize that I send a list.

What is the correct way to send a node list to the REST API?
Solution 1: Custom Endpoint

Unfortunately, entities are expected to be created one by one when using RESTful web services. You can create your own web service endpoint by writing a custom module and there, you can create support for creating multiple nodes with a single request. However, you'll still have to use batches of say, 50 nodes per request for things to work smoothly. This is more of a push import.

You might also want to try the jsonapi module to see if supports importing multiple operations in a single request.

Solution 2: Migrate API

Have you considered Drupal's migrate API instead? With migrate, you can import nodes from a remote XML / JSON document with a simple drush command which you can setup as a part of cron on your server. You can update existing items and create non-existing items. Migrate will also create nodes one by one, but it will be much faster than REST requests because it will not involve 1 HTTP request per node. This is more of a pull import.