cmprovision icon indicating copy to clipboard operation
cmprovision copied to clipboard

access project selected scripts in API

Open twebster801 opened this issue 1 year ago • 2 comments

I can access the projects in the api and the scripts in the api but is there a way to see what scripts are selected for a project and possible push a new script through the api for a specific project?

twebster801 avatar Aug 13 '24 14:08 twebster801

Not something supported out of the box.

Although you can modify api.php to get the scripts as well.

E.g. if you want all script information included change https://github.com/raspberrypi/cmprovision/blob/main/routes/api.php#L34:L36 to:

Route::middleware('auth:sanctum')->get('/projects', function (Request $request) {
    return Project::orderBy('name')->with('scripts')->get();
});

Or if you just want script IDs:

Route::middleware('auth:sanctum')->get('/projects', function (Request $request) {
    return Project::orderBy('name')->with(['scripts' => function($query) { $query->select('id'); }])->get();
});

maxnet avatar Aug 13 '24 19:08 maxnet

awesome I'll give that a try

twebster801 avatar Aug 13 '24 20:08 twebster801