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:

  1. Standard install of Drupal
  2. Enable the following core modules: HAL, HTTP Basic Authentication, RESTful Web Services, Serialization
  3. 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
  4. Create a new content type (/admin/structure/types/add)
  5. Set permissions on new content type
  6. Establish a REST session, logged in as user with appropriate permissions for REST calls and node creation (for the new content type)
  7. 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]

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):

Comments

ptwob132 created an issue. See original summary.

AlxVallejo’s picture

Are you saying that clearing caches fixes this issue?

wim leers’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

It's not [drupal path]/entity/node, but [drupal path]/node. I suspect this is the cause for getting that error.

dawehner’s picture

Just an idea, could we throw some helpful message to people if they POST to the wrong URL.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Fixed

Two months without response, and AFAICT the problem has been diagnosed. Feel free to reopen later.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

suresh.senthatti’s picture

Hi,

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."}

husninazer’s picture

Flushing all caches worked for me.