FarmOS.app: Error 404 Not Found

Hi everyone,

I’m self-hosting farmOS 3.x using Docker and I’m having trouble logging in via Field Kit (farmos.app). Every time I try to connect using my farm’s domain, I get a 404 Not Found error.

After checking the browser console, I noticed that the app is failing to fetch: GET https://farm.mydomain.com/api/field_module/field_module

  • I already have and working the field kit module
  • Even I tried to reinstall all FarmOS to get cleanest as posible

It seems like the Field Kit API endpoint is not being registered. Am I missing a configuration step to “expose” the field modules through the API in version 3.x?

1 Like

Hi @lluisgl - welcome to the community! :smiley:

This may be a bug in farmOS. I have a hunch that it was caused by this change:

That changed the way that API endpoints are exposed, and it looks like we didn’t make the necessary change to the farm_fieldkit module at the same time, so it’s likely been broken for a while.

Unfortunately, Field Kit and farmOS.app haven’t been updated in a while, and are not being actively maintained. We are actually planning on moving the farm_fieldkit module out of farmOS core and into a community add-on module in farmOS v4. So if you do end up using it, you will need to download that module separately after you upgrade. farmOS v4 has not been released yet, but we are getting close…

The good news is the fix is very simple. I think it will only require adding a single file. However, we won’t be fixing it in farmOS core in 3.x, so if you want to use Field Kit in 3.x you will need to fix it manually.

Try this:

Add a file called ApiHooks.php in /opt/drupal/web/profiles/farm/modules/core/fieldkit/src/Hook/ with the following content:

<?php

declare(strict_types=1);

namespace Drupal\farm_fieldkit\Hook;

use Drupal\Core\Hook\Attribute\Hook;

/**
 * API hook implementations for farm_fieldkit.
 */
class ApiHooks {

  /**
   * Implements hook_farm_api_allow_resource_types().
   */
  #[Hook('farm_api_allow_resource_types')]
  public function farmApiAllowResourceTypes() {
    return [
      'field_module',
    ];
  }

}

Let me know if that works. If it does, then I will commit the same file to the new 4.x contrib farm_fieldkit module, so it is ready for when you upgrade:

I committed this to a branch of the 4.x module here, for reference: Comparing 4.x...4.x-fix-api · farmOS/farm_fieldkit · GitHub

I will wait to merge that until I get confirmation that it fixes the issue.