简体   繁体   中英

Drupal8 REST-api for taxonomy terms do not work

I am writing an Angular2 web app with Drupal8 in the backend. I need to convert taxonomy id's to their respective labels, for that I want to use the API endpoint "/taxonomy/term/{taxonomy_term}". I have enabled the correct REST-API and given access to all roles, however when I try to access that end-point with an ID and ?_format=json, I get the message '{"message":"Not acceptable format: json"}'. If I remove the ?format=json, however, it gives me the results I want in HTML.

This error message is found in the file /core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php and is preceded by the following comment:

   // If this is a render array then we assume that the router went with the
    // generic controller and not one with a format. If the format requested is
    // not HTML though we can also assume that the requested format is invalid
    // so we provide a 406 response.

Can anyone help me with this? Alternatively, I will have to scrape the taxonomy label from the HTML-result.

In Structure > Views , disable the "Taxonomy term" view.

This view overrides the /taxonomy/term/{taxonomy_term} endpoint created by RESTful Web Services module. It won't accept JSON-format requests unless you add a "REST Export" display yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM