1

I'm running Craft CMS 2.6.2972 so I had to use the older Element API plugin.

I have downloaded the zip and then copied just the "elementapi" file in the zip to the plugin's folder.

Then I installed the plugin in the admin panel.

Then I made a file craft/config/elementapi.php with the contents

<?php
namespace Craft;

return [
    'endpoints' => [
        'news.json' => [
            'elementType' => 'Entry',
            'criteria' => ['section' => 'news'],
        ]
    ]
];

But if I hit the URL <myserver>/api/news.json then I get the following error:

2017/05/12 17:31:47 [error] [exception.Craft\HttpException.404] exception 'Craft\HttpException' in C:\inetpub\wwwroot\craft\app\controllers\TemplatesController.php:59 Stack trace:
#0 [internal function]: Craft\TemplatesController->actionRender('api/news.json', Array)
#1 C:\inetpub\wwwroot\craft\app\framework\web\actions\CAction.php(109): ReflectionMethod->invokeArgs(Object(Craft\TemplatesController), Array)
#2 C:\inetpub\wwwroot\craft\app\framework\web\actions\CInlineAction.php(47): CAction->runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
#3 C:\inetpub\wwwroot\craft\app\framework\web\CController.php(308): CInlineAction->runWithParams(Array)
#4 C:\inetpub\wwwroot\craft\app\framework\web\CController.php(286): CController->runAction(Object(CInlineAction))
#5 C:\inetpub\wwwroot\craft\app\framework\web\CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#6 C:\inetpub\wwwroot\craft\app\framework\web\CWebApplication.php(282): CController->run('render')
#7 C:\inetpub\wwwroot\craft\app\framework\web\CWebApplication.php(141): CWebApplication->runController('templates/rende...')
#8 C:\inetpub\wwwroot\craft\app\etc\web\WebApp.php(290): CWebApplication->processRequest()
#9 C:\inetpub\wwwroot\craft\app\framework\base\CApplication.php(185): Craft\WebApp->processRequest()
#10 C:\inetpub\wwwroot\craft\app\index.php(62): CApplication->run()
#11 C:\inetpub\wwwroot\public\index.php(14): require_once('C:\\inetpub\\wwwr...')
#12 {main} REQUEST_URI=/api/news.json
---

What might be wrong?

This is running on IIS and I've added .json to the mime types for the site.

This error is the same error as an unhandled link/route. So seems like it's not picking up the config or I have the wrong URL. The plugin did install ok.

  • 2
    If you're hitting /api/news.json in the browser, pretty sure the endpoint should be defined as 'api/news.json' => [. – Brad Bell May 12 '17 at 23:14
  • Thanks That was it althought the example doesnt show it like that. If you want to make this an answer can give you credit. – Tim May 15 '17 at 19:04
  • Fair enough... done! – Brad Bell May 15 '17 at 20:07
1

If you're hitting /api/news.json in the browser, you'd want to define the endpoint as 'api/news.json' as well. i.e.

<?php
namespace Craft;

return [
    'endpoints' => [
        'api/news.json' => [
            'elementType' => 'Entry',
            'criteria' => ['section' => 'news'],
        ]
    ]
];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.