Skip to content

[API Request]: /api/search to return url to result #3080

Description

@danpoltawski

API Endpoint or Feature

Thanks for adding /api/search endpoint :) One attribute that this endpoint doesn't return is a url which is directly linkable - it seems as an API consumer I need to do additional business logic/API calls to get a URL to be able to link to the result.

Use-Case

I have an external system which displays related bookstack results by querying on a tag, I want to just display a list of search results in the external system and directly link to them using a single API call (and ideally not get into the internal details of bookstack pages/chapters/shelves etc)

i.e.

 $resp = $client->get("https://bookstack/api/search?query=[Tagname={$tagvalue}]");
 $response = json_decode($resp->getBody());
 foreach  ($response->data as $result) {
        $o.="<li><a target='_blank' href='{$result->url}'>{$result->name}</a></li>\n";        
 }   

Additional context

I quickly hacked in this locally with the following patch - if this approach is valid, i'd be happy to update tests etc and prepare a pull request.

diff --git a/app/Http/Controllers/Api/SearchApiController.php b/app/Http/Controllers/Api/SearchApiController.php
index ba960b9d..0a9d2df1 100644
--- a/app/Http/Controllers/Api/SearchApiController.php
+++ b/app/Http/Controllers/Api/SearchApiController.php
@@ -52,9 +52,10 @@ class SearchApiController extends ApiController
                 'id', 'name', 'slug', 'book_id',
                 'chapter_id', 'draft', 'template',
                 'created_at', 'updated_at',
-                'tags', 'type',
+                'tags', 'type', 'url',
             ]);
             $result->setAttribute('type', $result->getType());
+            $result->setAttribute('url', $result->getURL());
         }
 
         return response()->json([

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions