Install the Company Roles Backend API

Edit on GitHub

This document describes how to install the Company Roles Backend API, which exposes company role data at /company-roles and the permissions a role can hold at /company-role-permissions through the Glue Backend application. Both resources ship together and are installed by this guide. For the endpoint reference, see Backend API: Manage company roles and Backend API: Manage company role permissions.

Prerequisites

Install the required features:

NAME VERSION INSTALLATION GUIDE
Spryker Core 202608.0 Install the Spryker Core feature
Company Account 202608.0 Install the Company Account feature
API Platform — Enable API Platform

Step 1 installs the remaining modules the API depends on, so you do not have to install them beforehand.

API Platform is required

The /company-roles and /company-role-permissions resources are generated by API Platform, which is not enabled in every project. If your project does not serve any API Platform resource on the Glue Backend application yet, complete Enable API Platform first—this guide assumes the Glue Backend application already boots with SprykerApiPlatformBundle registered.

Install feature core

1) Install the required modules

Install the feature using Composer:

composer require spryker-feature/customer-experience-management --update-with-dependencies
Verification

Make sure the following modules have been installed:

MODULE MINIMUM VERSION EXPECTED DIRECTORY
ApiPlatform — vendor/spryker/api-platform
CompanyRole — vendor/spryker/company-role
Permission — vendor/spryker/permission
CustomerExperienceManagement — vendor/spryker-feature/customer-experience-management

The feature pins the module versions it needs in its own composer.json, so step 1 resolves them for you. spryker/api-platform comes from enabling API Platform, which is a prerequisite of this guide.

2) Check the API Platform configuration

The resource schemas ship inside the installed package, at vendor/spryker-feature/customer-experience-management/resources/api/backend/company-roles.resource.yml and company-role-permissions.resource.yml. The generator finds them as long as the Glue Backend application serves the backend API type and scans the directory the feature is installed into.

In config/GlueBackend/packages/spryker_api_platform.php, confirm that apiTypes() includes backend. Leave sourceDirectories() alone unless your project overrides it—the default already covers installed packages. For what both settings do, see Configuration.

Projects that override sourceDirectories

If your project sets sourceDirectories() explicitly, add the directory the feature is installed into rather than replacing the list. Dropping the other entries hides every resource your project already serves.

Also confirm that config/GlueBackend/bundles.php registers SprykerApiPlatformBundle and ApiPlatformBundle. If it does not, your project has not enabled API Platform for the Glue Backend yet—see Enable API Platform.

3) Set up the database schema and transfer objects

Apply the database schema changes and generate the transfer objects:

docker/sdk console transfer:generate
docker/sdk console propel:install
This step adds a column

CustomerExperienceManagement declares the uuid column on spy_company_role, so so the Backend API no longer depends on another module to supply it. Projects that already installed the Company Account Glue API have the column and the migration is a no-op; every other project gains the column here. Until propel:install has run, the API cannot resolve any company role.

4) Back-fill the company role UUIDs

The UUID behavior fills uuid when a company role is saved, so roles that existed before the column was added have an empty uuid and cannot be addressed by the API. Generate the missing values:

docker/sdk console uuid:generate CompanyRole spy_company_role
Verification

Make sure every row has a UUID:

select count(*) from spy_company_role where uuid is NULL;

The result must be 0.

5) Synchronize the permissions

/company-role-permissions lists the permission plugins registered in your project, joined with the spy_permission rows that store them. A permission plugin that has never been synchronized is missing from that table and cannot be assigned to a role.

Permissions are written to spy_permission by the installer plugins that projects wire into InstallerDependencyProvider::getInstallerPlugins()—for example SharedCartPermissionInstallerPlugin and ShoppingListPermissionsInstallerPlugin. Run the installer:

docker/sdk console setup:init-db
Verification

Make sure the table is populated:

select count(*) from spy_permission;

The result must be greater than 0, and must cover every permission plugin your project registers in PermissionDependencyProvider. A permission that is registered as a plugin but missing here has no installer plugin writing it—add one for the module that owns the permission.

6) Generate the API resources

Generate the API resources, then clear the Glue Backend kernel cache:

docker/sdk cli "GLUE_APPLICATION=GLUE_BACKEND vendor/bin/glue api:generate"
rm -rf data/cache/GlueBackend/*
Verification

Make sure the generated resource classes exist at src/Generated/Api/Backend/CompanyRolesBackendResource.php and src/Generated/Api/Backend/CompanyRolePermissionsBackendResource.php. If they do not, the schemas were not discovered—check the sourceDirectories setting from step 2.

Verification

Request a Back Office access token as described in Authenticate as a Back Office user, then retrieve a company role collection.

Retrieve a company role collection

curl "https://glue-backend.mysprykershop.com/company-roles?page[limit]=1" \
  -H "Authorization: Bearer {access_token}" \
  -H "Accept: application/vnd.api+json"

The integration is successful when the request returns 200 with a data array and a meta.pagination object.

Retrieve the available permissions

curl "https://glue-backend.mysprykershop.com/company-role-permissions?page[limit]=5" \
  -H "Authorization: Bearer {access_token}" \
  -H "Accept: application/vnd.api+json"

The request returns 200 with one entry per permission, each carrying a key and its localizedNames. An empty collection means step 5 has not run.

Create a company role to confirm the write path:

curl -X POST "https://glue-backend.mysprykershop.com/company-roles" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/vnd.api+json" \
  -H "Accept: application/vnd.api+json" \
  -d '{"data":{"type":"company-roles","attributes":{"name":"Approver","companyUuid":"{company_uuid}","permissionKeys":["ApproveQuotePermissionPlugin"]}}}'

The request returns 201 Created with the created company role.

Troubleshooting

SYMPTOM CAUSE
404 with error code 007 while src/Generated/Api/Backend/CompanyRolesBackendResource.php exists The route is unknown to the API Platform kernel, so the Glue router answered instead. The kernel cache is stale—check that you removed the directory that actually exists under data/cache/GlueBackend/, then re-run step 6 in order. The Glue container’s standard error stream names the real cause: docker logs <glue-backend-container> --since 5m 2>&1 | grep -i exception. See API Platform troubleshooting.
404 on /company-roles and no generated resource class The schema was not discovered. Confirm that spryker/api-platform is installed, and, if your project overrides sourceDirectories(), that it still covers the directory the feature is installed into.
404 with error code 1218 for a company role you can see in the Back Office That role’s uuid is empty. Run step 4, or save the role once in the Back Office to have the UUID behavior fill the column.
404 with error code 1213 when creating a company role The company named by companyUuid was not found, or that company’s uuid column is empty. Companies carry their own uuid, filled by the UUID behavior when the company is saved.
422 with error code 1233 for a permission the Back Office offers The permission plugin is registered but has no spy_permission row, so the API cannot resolve its key. Run step 5, and confirm the module that owns the permission contributes an installer plugin.
/company-role-permissions returns an empty collection spy_permission is empty, or no permission plugin is registered in PermissionDependencyProvider. Run step 5, then confirm the plugin stack.
Validation messages come back in English when another language was requested The feature ships its API messages as data/translation/Api/{locale}.csv inside the installed package, keyed by the English message. If they are not loaded, Symfony falls back to the message itself, so the response stays readable and the problem is easy to miss. Send Accept-Language and compare. Loading these files requires a spryker/api-platform version that reads them—update it to the latest version your project supports.