Skip to main content
NikoFischer.com

Main navigation

  • Home
  • About
    • My Reading List
    • Recommended Youtube Channels
    • Life Rules
    • Podcast
  • 50-Day Challenge
  • Impressum
Sprachumschalter
  • German
  • English

Breadcrumb

  1. Home

Drupal 9.1 REST: Post and patch requests are rejected

🎸
🚀 Beta Running

PYNGUP: Rebellion against toxic productivity

Beta limited to 100 spots. Tasks become social commitments instead of lonely to-dos.

🚀 Join Beta 📖 Read Story "€487 wasted"
By Niko, 11 February, 2021

For a few days now, I've been observing the same problem in various projects: post and patch requests on some Rest endpoints are being rejected with an Error 500.

Error message from Vue js: Error 500
Error 500: Error message from a Vue js web app when trying to access the Drupal REST endpoint with a post request.

The following error message can be found in the Drupal logs:

Symfony\Component\Routing\Exception\MethodNotAllowedException: in Drupal\Core\Routing\MethodFilter->filter()

The problem seems irrational: the REST Resources were all correctly created and enabled via the Rest UI module with POST or PATCH method respectively, json selected as data format and cookie selected as authentication method.

Interesting: The problem only appeared on remote web servers. It did not happen in local development environments. All requests went through without a hitch.

Workaround: Adjust language settings

All affected pages were multilingual and mostly had "German" selected as the default language. Since all requests run on URLs that are not prefixed with a language selection, I suspect this is a problem in the Drupal routing system. If you call a URL without a language prefix - for example example.com/demo instead of example.com/en/demo - then Drupal internally redirects to the URL with the language prefix. Presumably, this will result in a change to the request header.

.

As a workaround, it helps to adjust the language setting in the user profile. There the value for "Administration page language" should be set to "No preference".

Set Admin Page Language to No preference

 

Tags

  • Drupal
  • REST
  • Error

Comments

About text formats

Restricted HTML

  • Allowed HTML tags: <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Related articles

CORS is not meant to secure an API endpoint
Upgrading Drupal 9 to Drupal 10 Using Composer
How to Change the Title of a Drupal Form (Drupal 9 & 10)
The Future of Drupal: A Comprehensive Analysis and Forecast
The 5 Best Drupal Modules for Bloggers in 2024

About the author

Nikolai Fischer is the founder of Kommune3 (since 2007) and a leading expert in Drupal development and tech entrepreneurship. With 17+ years of experience, he has led hundreds of projects and achieved #1 on Hacker News. As host of the "Kommit mich" podcast and founder of skillution, he combines technical expertise with entrepreneurial thinking. His articles about Supabase, modern web development, and systematic problem-solving have influenced thousands of developers worldwide.

Ihre Anmeldung konnte nicht gespeichert werden. Bitte versuchen Sie es erneut.
Ihre Anmeldung war erfolgreich.

Newsletter

Join a growing community of friendly readers. From time to time I share my thoughts about rational thinking, productivity and life.

Nikolai Fischer

✌ Hi, I'm Niko
Entrepreneur, developer & podcaster

Contact me:

  • E-Mail
  • Phone
  • LinkedIn

My Reading List

  • $100M Leads: How to Get Strangers To Want To Buy Your Stuff - Alex Hormozi
  • Quantitative Trading: How to Build Your Own Algorithmic Trading Business (Wiley Trading) - Ernest P. Chan
  • Hands-On Machine Learning for Algorithmic Trading: Design and implement investment strategies based on smart algorithms that learn from data using Python - Stefan Jansen
  • Algorithmic Trading - Ernie Chan
  • Let Me Tell You a Story: Tales Along the Road to Happiness - Jorge Bucay
more
RSS feed