I was experimenting with API endpoints construction, by using the suggested October CMS 3 method.
Everything was working fine, but all of a sudden I get 404 errors, when making the requests. I found that the requests only work from the browser if I’m logged in to the October CMS backend.
Previously, the requests worked without being authenticated and also from Postman or the Thunder Client in Visual Studio Code.
The only change I’m aware of is the installation of two extensions for VSC: “October Twig” and “October Tools”.
This is an example of my setup:
I have a page in the active template: “apiv1_blogposts.htm”
This is the code:
title = "Blog Posts"
layout = "default"
url = "/api-v1/blogposts/:status?published/:language?en"
[collection blogposts]
handle = "Content\BlogPost"
==
{% set result = collect() %}
{% set selectedPosts = blogposts.where('status', this.param.status).get() %}
{% for post in selectedPosts %}
{% do result.push({
id: post.id,
title: post.title,
lang: post.language,
status: post.status,
created_at: post.created_at,
updated_at: post.updated_at,
content: post.content,
param: this.param.status
}) %}
{% endfor %}
So, If I test this URL:
http://localhost:8082/api-v1/blogposts
I get a 404 error page, except if the backend user session is initiated.
What I am missing?
Thanks in advance.