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: <obtained from http://example.com/rest/session/token>' \
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: <obtained from http://example.com/rest/session/token>' \
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?
Drupal\rest\Plugin\rest\resource\EntityResource
, all of the code and supporting comments suggest you can only create one entity at a time. Indeed the only parameter to thepost()
method isEntityInterface $entity
, rather than an array. Maybe you can impose some middleware in the way which changes that, or perhaps write your own resource