When adding a new content type, REST calls to that content type do not work unless cache is cleared manually.
Once Drupal site is configured for REST calls on node entities, any new Content Types (which are defined after modules are enabled) give the following error during POST & PATCH (I tested using hal+json format) calls to the site:
{"error":"Type http:[drupal path]/[**new content type**] does not correspond to an entity on this site."}
All permissions were set correctly for the new content type.
Steps required to reproduce the bug:
- Standard install of Drupal
- Enable the following core modules: HAL, HTTP Basic Authentication, RESTful Web Services, Serialization
- Install contributed module: REST UI (I don't think this is necessary to reproduce, but I didn't test without it):
- Configure REST: REST UI Configuration for Content resource - //node/(node):
- GET - authentication: basic_auth, cookie - formats: hal_json, json
- POST - authentication: basic_auth, cookie - formats: hal_json, json
- DELETE - authentication: basic_auth, cookie - formats: hal_json, json
- PATCH - authentication: basic_auth, cookie - formats: hal_json, json
- Configure REST: REST UI Configuration for Content resource - //node/(node):
- Create a new content type (/admin/structure/types/add)
- Set permissions on new content type
- Establish a REST session, logged in as user with appropriate permissions for REST calls and node creation (for the new content type)
- Make a REST call to create a new instance of the new content type:
- method:
"POST" - url:
"[drupal path]/entity/node" - contentType:
"application/hal+json" - data:
{"_links":{"type":{"href":"[drupal path]/rest/type/node/[**new content type name**]"}}, "title":[{"value":"sample title"}]} - headers:
"X-CSRF-Token": [token]
- method:
Expected behavior:
New node created, response 201 created
Instead:
The following error reported in the 401 Bad Request response:
{"error":"Type http:[drupal path]/rest/type/node/[**new content type**] does not correspond to an entity on this site."}
Workaround:
"Clear all caches" after creating a new Content Type (/admin/config/development/performance)
Configuration details:
- Apache Version: 2.2.31
- Architecture: x86_64
- Operating System: linux
- PHP Version: 5.6.11
- MySQL Version: 5.5.42-37.1-log
- Drupal Core: drupal 8.0.0-rc2
- Drupal enabled modules (in addition to standard Drupal install):
- HAL
- HTTP Basic Authentication
- RESTful Web Services
- Serialization
- REST UI (https://www.drupal.org/project/restui)
Comments
Comment #2
AlxVallejo commentedAre you saying that clearing caches fixes this issue?
Comment #3
wim leersIt's not
[drupal path]/entity/node, but[drupal path]/node. I suspect this is the cause for getting that error.Comment #4
dawehnerJust an idea, could we throw some helpful message to people if they
POSTto the wrong URL.Comment #5
wim leersTwo months without response, and AFAICT the problem has been diagnosed. Feel free to reopen later.
Comment #7
suresh.senthatti commentedHi,
When i'm updating the node, i'm getting the same problem.
{"error":"Type http:[drupal path]/rest/type/node/[**new content type**] does not correspond to an entity on this site."}
Comment #8
husninazer commentedFlushing all caches worked for me.