#[Route(path: '/api/integration', name: 'api.integration.create', methods: ['POST'], defaults: ['_acl' => ['integration:create']])]
public function upsertIntegration(?string
$integrationId, Request
$request, Context
$context, ResponseFactoryInterface
$factory): Response
{ /** @var AdminApiSource $source */
$source =
$context->
getSource();
$data =
$request->request->
all();
// only an admin is allowed to set the admin field
if ( !
$source->
isAdmin() &&
isset($data['admin'
]) ) { throw new PermissionDeniedException();
} if (!
isset($data['id'
])) { $data['id'
] = null;
} $data['id'
] =
$integrationId ?:
$data['id'
];
$events =
$context->
scope(Context::SYSTEM_SCOPE,
fn (Context
$context): EntityWrittenContainerEvent =>
$this->integrationRepository->
upsert([$data],
$context));