Skip to content

Latest commit

 

History

History
261 lines (152 loc) · 6.94 KB

apidoc.md

File metadata and controls

261 lines (152 loc) · 6.94 KB

AmCAT4 API Documentation

Please see the tabs below for the various API endpoints. See also the GitHub pages for the API/backend and client bindings for Python and R.

Note: To generate this documentation, run python -m amcat4 document

Querying

API Endpoints for querying

POST /index/<index>/aggregate

    Construct an aggregate query. POST body should be a json dict with axes and/or aggregations keys,
    and optional filters and queries keys:
    :axes: list of dicts containing field and optional interval: [{'field': .., ['interval': ..]}, ...],
    :aggregations: list of dicts containing field, function, and optional name: [{field, function, [name]}, ...]
    :filters: see POST /query endpoint,
    :queries: see POST /query endpoint,
     }

    For example, to get average views per week per publisher
    {
     'axes': [{'field': 'date', 'interval':'week'}, {'field': 'publisher'}],
     'aggregations': [{'field': 'views', 'function': 'avg'}]
    }

    Returns a JSON object {data: [{axis1, ..., n, aggregate1, ...}, ...], meta: {axes: [...], aggregations: [...]}
    

POST /index/<index>/query

    List or query documents in this index. POST body should be a json dict structured as follows (all keys optional):


    {
        # Sorting
        'sort': 'date'                        # sort by date
        'sort': ['date', 'id']                # sort by date, then by id
        'sort': [{'date': {'order':'desc'}}]  # sort by date in descending order (see elastic docs below)
        # Docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html

        # Pagination
        'sort':
        'per_page': <number>            # Number of documents per page
        'page': <number>                # Request a specific page
        'scroll': <string>              # Create a scroll request. Value should be e.g. 5m for 5 minutes
        'scoll_id': <string>            # Get the next page for the scroll request

        # Control highlighting
        'annotations': true                        # Return _annotations with query matches as annotations
        'highlight': true                          # Highlight document. True highlights whole document
        'highlight': {'number of fragments': 3}    # Highlight up to 3 snippets per document (see elastic docs below)
        # Docs: https://www.elastic.co/guide/en/elasticsearch/reference/7.17/highlighting.html

        # select fields
        'fields': field                                    ## single field
        'fields': [field1, field2]                         ## multiple fields

        # elastic queries.
        'queries':  query,                               ## single query
        'queries': [query1, query2],                     ## OR without labels
        'queries': {label1: query1, label2: query2}      ## OR with labels

        # filters
        'filters': {field: value},                       ## exact value
                   {field: [value1, value2]},            ## OR
                   {field: {gt(e): value, lt(e): value}  ## range or multiple
                   {field: {values: [v1,v2]}             ## can also use values inside dict
        }
    }

    Returns a JSON object {data: [...], meta: {total_count, per_page, page_count, page|scroll_id}}
    }

    

Documents

API Endpoints for document and index management

GET /index/

    List index from this server. Returns a list of dicts containing name, role, and guest attributes
    

POST /index/

    Create a new index, setting the current user to admin (owner).
    POST data should be json containing name and optional guest_role
    

PUT /index/<ix>

    Modify the index. Currently only supports modifying guest_role
    POST data should be json containing the changed values (i.e. guest_role)
    

GET /index/<ix>

    Modify the index. Currently only supports modifying guest_role
    POST data should be json containing the changed values (i.e. guest_role)
    

DELETE /index/<ix>

    Delete the index.
    

POST /index/<ix>/documents

    Upload documents to this server.
    JSON payload should contain a `documents` key, and may contain a `columns` key:
    {
      "documents": [{"title": .., "date": .., "text": .., ...}, ...],
      "columns": {<field>: <type>, ...}
    }
    Returns a list of ids for the uploaded documents
    

GET /index/<ix>/documents/<docid>

    Get a single document by id
    GET request parameters:
    fields - Comma separated list of fields to return (default: all fields)
    

PUT /index/<ix>/documents/<docid>

    Update a document
    PUT request body should be a json {field: value} mapping of fields to update
    

GET /index/<ix>/fields

    Get the fields (columns) used in this index
    returns a json array of {name, type} objects
    

POST /index/<ix>/fields

    Set the field types used in this index
    POST body should be a dict of {field: type}
    

GET /index/<ix>/fields/<field>/values

    Get the fields (columns) used in this index
    

Authentication

AmCAT4 can use either Basic or Token-based authentication. A client can request a token with basic authentication and store that token for future requests.

GET /auth/token

    Create a new token for the authenticated user
    

Users

AmCAT4 can use either Basic or Token-based authentication. A client can request a token with basic authentication and store that token for future requests.

POST /users/

    Create a new user. Request body should be a json with email, password, and optional (global) role
    

GET /users/<email>

    View the current user. Users can view themselves, writer can view others
    

DELETE /users/<email>

    Delete the given user. Users can delete themselves, admin can delete everyone, and writer can delete non-admin
    

PUT /users/<email>

    Modify the given user.
    Users can modify themselves (but not their role), admin can change everyone, and writer can change non-admin.
    

GET /users/all

None