Drupal 9 - curl POST returns "No route found for POST /entity/node" error

By xngo on December 28, 2021


My test curl command to post a simple new article content type was working fine in Drupal 8.9.20 but after I upgraded to Drupal 9.3.0, that command no longer works. It returned the following error message:

{"message":"No route found for \u0022POST \/entity\/node\u0022"}


After wasting more than half a day searching for a solution and almost want to give up the upgrade to Drupal 9, I found the following ambiguous statement from https://www.drupal.org/node/2098511.

Prior to Drupal 8.3.0, instead of /node POST to /entity/node - deprecated and will be removed in Drupal 9.

I played around and instead of using ${BOT_DOMAIN}/entity/node, I used ${BOT_DOMAIN}/node and it works. My final curl command is:

curl --include \
      --request POST \
      --user "${BOT_USERNAME}:${BOT_PASSWORD}" \
      --header 'Content-type: application/hal+json' \
      ${BOT_DOMAIN}/node?_format=hal_json \
       --data-binary "@${json_file}"

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.