Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 Not Found — JSON URL / UrlHelper #173

Open
a-rbsn opened this issue Dec 5, 2022 · 1 comment
Open

404 Not Found — JSON URL / UrlHelper #173

a-rbsn opened this issue Dec 5, 2022 · 1 comment
Labels

Comments

@a-rbsn
Copy link

a-rbsn commented Dec 5, 2022

Description

I'm using the UrlHelper to generate JSON URLs for entries but the generated URL doesn't seem to work.

Steps to reproduce

        'projects.json' => function () {
            Craft::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', '*');
            return [
                'elementType' => Entry::class,
                'criteria' => [
                    'section' => 'projects',
                ],
                'paginate' => false,
                'transformer' => function (Entry $entry) {

                    return [
                        'id' => $entry->id,
                        'slug' => $entry->slug,
                        'jsonUrl' => UrlHelper::url("project/{$entry->slug}.json"),
                    ];
                },
            ];
        },
        'project/<entrySlug>.json' => function ($entrySlug) {
            Craft::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', '*');
            return [
                'elementType' => Entry::class,
                'criteria' => [
                    'section' => 'projects',
                    'slug' => $entrySlug,
                ],
                'one' => true,
                'transformer' => function (Entry $entry) {
                    return [
                        'id' => $entry->id,
                        'title' => $entry->title,
                        'slug' => $entry->slug,
                    ];
                },
            ];
        },

Additional info

  • Craft version: 4.3.4
  • PHP version: 8.2
  • Database driver & version: MySQL
  • Plugins & versions: ElementAPI 3.0.1.1
@a-rbsn a-rbsn added the bug label Dec 5, 2022
@brianjhanson
Copy link

Can you add any detail about how it doesn't work and your particular config? Are the correct URLs being generated? Or are you getting an unexpected URL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants