(zettel (meta (box-name "manual") (created "20220912111111") (modified "20260729135524") (precursor "00001012051200") (role "manual") (syntax "zmk") (tags "#api #manual #zettelstore") (title "API: Query the list of all zettel")) (rights read) (content "" "The [[endpoint|00001012920000]] ''/z'' also allows you to filter the list of all zettel[^If [[authentication is enabled|00001010040100]], you must include a valid [[access token|00001012050200]] in the ''Authorization'' header] and optionally specify some actions.\n\nA [[query|00001007700000]] consists of an optional [[search expression|00001007700000#search-expression]] and an optional [[list of actions|00001007700000#action-list]] ([[described below|#actions]]).\nIf you provide no search expression, all zettel are selected.\nSimilarly, if you specify no valid action, or the action list is empty, the list of all selected zettel metadata is returned.\n\nSearch expression and action list are separated by a vertical bar character (\"\"''|''\"\", U+007C), and must be given with the ''q'' query parameter.\n\nThe query parameter \"\"''q''\"\" allows you to specify a [[query expression|00001007700000]] for a full-text search of all zettel content and / or restricting the search according to specific metadata.\n\nThe query parameter can be provided multiple times.\nQuery expressions are combined with a logical **AND**.\n\nThis loosely resembles the search form of the [[web user interface|00001014000000]] or those of [[Zettelmarkup's Query Transclusion|00001007031140]].\n\nFor example, if you want to retrieve all zettel that contain the string \"\"API\"\" in their title, your request will be:\n```sh\n# curl 'http://127.0.0.1:23123/z?q=title%3AAPI+ORDER+REVERSE+id+OFFSET+1'\n00001012921200 API: Encoding of Zettel Access Rights\n00001012921000 API: Structure of an access token\n00001012920500 Encodings available via the API\n00001012920000 Endpoints used by the API\n...\n```\n\nIf you want to retrieve a data document, as a [[symbolic expression|00001012930500]]:\n\n```sh\n# curl 'http://127.0.0.1:23123/z?q=title%3AAPI+ORDER+REVERSE+id+OFFSET+1&enc=data'\n(meta-list (query \"title:API ORDER REVERSE id OFFSET 1\") (human \"title HAS API ORDER REVERSE id OFFSET 1\") (zettel \"00001012921200\" (meta (back \"00001012051200 00001012051400 00001012053200 00001012053300 00001012053400 00001012054200 00001012920528\") (backward \"00001012051200 00001012051400 00001012053200 00001012053300 00001012053400 00001012054200 00001012920528\") (box-name \"manual\") (created \"20220201173115\") (forward \"00001003000000 00001006020400 00001010040100 00001010040200 00001010070200 00001010070300\") (modified \"20260714200809\") (published \"20260714200809\") (role \"manual\") (syntax \"zmk\") (tags \"#api #manual #reference #zettelstore\") (title \"API: Encoding of Zettel Access Rights\")) (rights create read update delete)) (zettel \"00001012921000\" (meta (back \"00001012050600\") (backward \"00001012050200 00001012050400 00001012050600\") (box-name \"manual\") (created \"20210126175322\") (forward \"00001012050200 00001012050400 00001012930000 00001012930500\") (modified \"20260605144534\") (published \"20260605144534\") (role \"manual\") (syntax \"zmk\") (tags \"#api #manual #reference #zettelstore\") (title \"API: Structure of an access token\") ...\n```\n\nThe data object contains a key ''\"meta-list\"'' to signal that it contains a list of metadata values (and some more).\nIt contains the keys ''\"query\"'' and ''\"human\"'' with a string value.\nBoth will contain a textual description of the underlying query if you select only some zettel with a [[query expression|00001007700000]].\nWithout a selection, the values are the empty string.\n''\"query\"'' returns the normalized query expression itself, while ''\"human\"'' is the normalized query expression to be read by humans.\n\nThen comes the list of zettel data.\nData of a zettel is indicated by the symbol ''zettel'', followed by the zettel identifier as a string value.\nMetadata starts with the symbol ''meta'', and each metadatum itself is a list of metadata key / metadata value.\nMetadata keys are encoded as a symbol, metadata values as a string.\n''\"rights\"'' encodes the [[access rights|00001012921200]] for the given zettel.\n\n=== Aggregates\n\nAn implicit precondition is that the zettel must contain the given metadata key.\nFor metadata keys like [[''title''|00001006020000#title]], which have a default value, this precondition should always be true.\nBut the situation is different for a key like [[''url''|00001006020000#url]].\nBoth ``curl 'http://localhost:23123/z?q=url%3A'`` and ``curl 'http://localhost:23123/z?q=url%3A!'`` may result in an empty list.\n\n\nAs an example for a query action, to list all roles used in the Zettelstore, send an HTTP GET request to the endpoint ''/z?q=|role''.\n\n```sh\n# curl 'http://127.0.0.1:23123/z?q=|role'\nconfiguration\t00001000000100 00000000090002 00000000090000 00000000040001 00000000025001 00000000020001 00000000000100 00000000000092 00000000000090 00000000000006 00000000000005 00000000000004 00000000000001\nmanual\t00001018000000 00001017000000 00001014000000 00001012921200 00001012921000 00001012920800 00001012920588 00001012920584 00001012920582 00001012920522 00001012920519 00001012920516 00001012920513 00001012920510 00001012920503 00001012920500 00001012920000 00001012080500 00001012080200 00001012080100 00001012070500 00001012054600 00001012054400 00001012054200 00001012054000 00001012053900 00001012053800 00001012053600 00001012053500 00001012053400 00001012053300 00001012053200 00001012051400 00001012051200 00001012050600 00001012050400 00001012050200 00001012000000 00001010090100 00001010070600 00001010070400 00001010070300 00001010070200 00001010040700 00001010040400 00001010040200 00001010040100 00001010000000 00001008050000 00001008010500 00001008010000 00001008000000 00001007990000 00001007906000 00001007903000 00001007900000 00001007800000 00001007790000 00001007780000 00001007706000 00001007705000 00001007702000 00001007700000 00001007050200 00001007050100 00001007050000 00001007040350 00001007040340 00001007040330 00001007040324 00001007040322 00001007040320 00001007040310 00001007040300 00001007040200 00001007040100 00001007040000 00001007031400 00001007031300 00001007031200 00001007031140 00001007031110 00001007031100 00001007031000 00001007030900 00001007030800 00001007030700 00001007030600 00001007030500 00001007030400 00001007030300 00001007030200 00001007030100 00001007030000 00001007020000 00001007010000 00001007000000 00001006055000 00001006050000 00001006036500 00001006036000 00001006035500 00001006035000 00001006034500 00001006034000 00001006033500 00001006033000 00001006032500 00001006032000 00001006031500 00001006031000 00001006030500 00001006030000 00001006020400 00001006020100 00001006020000 00001006010000 00001006000000 00001005090000 00001005000000 00001004101000 00001004100000 00001004059900 00001004059700 00001004051400 00001004051200 00001004051100 00001004051000 00001004050400 00001004050200 00001004050000 00001004020200 00001004020000 00001004011600 00001004011400 00001004011200 00001004010000 00001004000000 00001003600000 00001003315000 00001003310000 00001003305000 00001003300000 00001003000000 00001002000000 00001001000000 00001000000000\nzettel\t00010000000000 00000000090001\n```\n\nThe result is a text file.\nThe first word, separated by a horizontal tab (U+0009) contains the role name.\nThe rest of the line consists of zettel identifier, where the corresponding zettel have this role.\nZettel identifiers are separated by a space character (U+0020).\n\nPlease note that the list is **not** sorted by the role name, so the same request might result in a different order.\nIf you want a sorted list, you could sort it on the command line (``curl 'http://127.0.0.1:23123/z?q=|role' | sort``) or within the software that made the call to the Zettelstore.\n\nOf course, this list can also be returned as a data object:\n\n```sh\n# curl 'http://127.0.0.1:23123/z?q=|role&enc=data'\n(aggregate \"role\" (query \"| role\") (human \"| role\") (\"tag\" \"00001019990010\") (\"manual\" \"00001012921200\" \"00001007900000\" \"00001012920519\" \"00001007031000\" \"00001012930500\" \"00001003310000\" \"00001012053600\" \"00001004020200\" \"00001007040340\" \"00001007702000\" \"00001007720500\" \"00001012050600\" \"00001002000000\" \"00001006033000\" \"00001005000000\" \"00001007031200\" \"00001012920531\" \"00001008000000\" \"00001012080200\" \"00001012080100\" \"00001007990000\" \"00001012931600\" \"00001004011400\" \"00001004101000\" \"00001004010200\" \"00001004051100\" \"00001006000000\" \"00001007031110\" \"00001006030500\" \"00001007030500\" \"00001010040100\" \"00001012931000\" \"00001012920000\" \"00001006031000\" \"00001003000000\" \"00001006050000\" \"00001006020100\" \"00001007720900\" \"00001006020000\" \"00001006020400\" \"00001007770000\" \"00001007040322\" \"00001004059900\" \"00001014000000\" \"00001004020000\" \"00001004100000\" \"00001007010000\" \"00001006032500\" \"00001005090000\" \"00001012051400\" \"00001010070300\" \"00001007040320\" \"00001007040350\" \"00001012931900\" \"00001012054200\" \"00001007040330\" \"00001004059700\" \"00001008010800\" \"00001006033500\" \"00001007050000\" \"00001007020000\" \"00001006034000\" \"00001012054600\" \"00001010040700\" \"00001010070600\" \"00001007720300\" \"00001007906000\" \"00001007030100\" \"00001017000000\" \"00001007701000\" \"00001012050200\" \"00001010070200\" \"00001003300000\" \"00001004050200\" \"00001007040100\" \"00001004000000\" \"00001012930000\" \"00001012920525\" \"00001010040200\" \"00001007031300\" \"00001004010000\" \"00001007706000\" \"00001007031400\" \"00001000000000\" \"00001004050000\" \"00001007800000\" \"00001012051600\" \"00001006055000\" \"00001004051400\" \"00001007030000\" \"00001007031100\" \"00001007050100\" \"00001008010500\" \"00001010000000\" \"00001010070400\" \"00001012920800\" \"00001012921000\" \"00001012931400\" \"00001008010000\" \"00001006035000\" \"00001012053500\" \"00001003600000\" \"00001010040400\" \"00001008050000\" \"00001012920516\" \"00001007030900\" \"00001004051200\" \"00001007030200\" \"00001012051800\" \"00001007700000\" \"00001007705000\" \"00001007903000\" \"00001012931200\" \"00001007720000\" \"00001010090100\" \"00001012931800\" \"00001007030600\" \"00001007040000\" \"00001006034500\" \"00001007780000\" \"00001012051200\" \"00001018000000\" \"00001004011200\" \"00001007050200\" \"00001012920513\" \"00001006031500\" \"00001007040300\" \"00001003315000\" \"00001012000000\" \"00001012050400\" \"00001003305000\" \"00001007720600\" \"00001007710000\" \"00001004011600\" \"00001007721200\" \"00001007040200\" \"00001012920500\" \"00001012053200\" \"00001012920510\" \"00001004050400\" \"00001007030400\" \"00001007030800\" \"00001006030000\" \"00001001000000\" \"00001007040310\" \"00001007790000\" \"00001006035500\" \"00001006032000\" \"00001012053300\" \"00001006010000\" \"00001012080500\" \"00001007040324\" \"00001012070500\" \"00001007030700\" \"00001012920528\" \"00001007030300\" \"00001007031140\" \"00001012053800\" \"00001012920522\" \"00001004051000\" \"00001012053400\" \"00001007000000\") (\"configuration\" \"00001000000100\" \"00000000000100\" \"00000000090000\" \"00000000000007\" \"00001000000001\" \"00000000000005\" \"00000000025001\" \"00000000030001\" \"00000000090002\" \"00000000030101\" \"00000000080001\" \"00000000000006\" \"00000000000092\" \"00000000040001\" \"00000000000090\" \"00000000000001\" \"00000000090003\" \"00000000090001\" \"00000999999999\" \"00000000090004\" \"00000000000004\" \"00000000020001\") (\"role\" \"00000000060010\" \"00000000060020\" \"00001000000002\" \"00000000060040\" \"00000000060030\") (\"zettel\" \"00010000000000\") (\"material\" \"00001008010802\" \"00001008010801\" \"00001008010803\"))\n```\n\nThe data object starts with the symbol ''aggregate'' to signal a different format compared to ''meta-list'' above.\nThen a string follows, which specifies the key on which the aggregate was performed.\n''query'' and ''human'' have the same meaning as above.\nThen comes the result list of aggregates.\nEach aggregate starts with a string of the aggregate value, in this case the role value, followed by a list of zettel identifier, denoting zettel which have the given role value.\n\nSimilarly, to list all tags used in the Zettelstore, send an HTTP GET request to the endpoint ''/z?q=|tags''.\nIf successful, the output is a data object:\n\n```sh\n# curl 'http://127.0.0.1:23123/z?q=|tags&enc=data'\n(aggregate \"tags\" (query \"| tags\") (human \"| tags\") (\"#meta\" \"00001006030000\" \"00001006031500\" \"00001006033500\" \"00001006034000\" \"00001006034500\" \"00001006020000\" \"00001006032500\" \"00001006031000\" \"00001006020400\" \"00001006035000\" \"00001006020100\" \"00001006033000\" \"00001006032000\" \"00001006035500\") (\"#tutorial\" \"00001007900000\" \"00001007903000\" \"00001007906000\") (\"#example\" \"00001007790000\") (\"#design\" \"00001005000000\" \"00001006055000\" \"00001002000000\" \"00001006000000\" \"00001006050000\") (\"#security\" \"00001010040200\" \"00001010070200\" \"00001010040100\" \"00001010090100\" \"00001010040700\" \"00001010000000\" \"00001010070300\" \"00001010040400\" \"00001010070400\" \"00001010070600\") (\"#search\" \"00001007710000\" \"00001007700000\" \"00001007720500\" \"00001007706000\" \"00001007702000\" \"00001007720900\" \"00001007720600\" \"00001007790000\" \"00001007031140\" \"00001007720300\" \"00001007705000\" \"00001007701000\" \"00001007780000\" \"00001007720000\" \"00001007770000\") (\"#encryption\" \"00001010090100\") (\"#api\" \"00001012050400\" \"00001012080500\" \"00001012070500\" \"00001012920510\" \"00001012053800\" \"00001012054600\" \"00001012931600\" \"00001012931800\" \"00001012920500\" \"00001012051800\" \"00001012053200\" \"00001012920519\" \"00001012080200\" \"00001012053300\" \"00001012051200\" \"00001012920525\" \"00001012050600\" \"00001012931000\" \"00001012920516\" \"00001012921200\" \"00001012931900\" \"00001012920800\" \"00001012050200\" \"00001012051400\" \"00001012920528\" \"00001012921000\" \"00001012920000\" \"00001012931400\" \"00001012080100\" \"00001012920522\" \"00001012053600\" \"00001012931200\" \"00001012920513\" \"00001012000000\" \"00001012920531\" \"00001012053400\" \"00001012053500\" \"00001012051600\" \"00001012054200\") ...\n```\n\nIf you want only those tags that occur at least 100 times, use the endpoint ''/z?q=|MIN100+tags''.\nYou see from this that actions are separated by space characters.\n\n=== Actions\n\nThere are two types of actions: parameters and aggregates.\nThe following actions are supported:\n; ''MINn'' (parameter)\n: Emit only those values with at least __n__ aggregated values.\n __n__ must be a positive integer, ''MIN'' must be given in upper-case letters.\n; ''MAXn'' (parameter)\n: Emit only those values with at most __n__ aggregated values.\n __n__ must be a positive integer, ''MAX'' must be given in upper-case letters.\n; ''KEYS'' (aggregate)\n: Emit a list of all metadata keys, together with the number of zettel having the key.\n; ''REDIRECT'' (aggregate)\n: Performs an HTTP redirect to the first selected zettel, using HTTP status code 302.\n The zettel identifier is in the body.\n; ''REINDEX'' (aggregate)\n: Updates the internal search index for the selected zettel, similar to the [[refresh|00001012080500]] API call, and requires the same permissions.\n It is not technically an aggregate, since it is used primarily for its side effect.\n However, another aggregate may be specified.\n; Any [[metadata key|00001006020000]] of type [[Word|00001006035500]] or [[TagSet|00001006034000]] (aggregates)\n: Emit an aggregate of the given metadata key.\n The key can be given in any letter case.\n\nFirst, ''REINDEX'' actions are executed, then ''REDIRECT''.\nIf no ''REDIRECT'' was found the first other aggregate action will be executed.\n\nTo allow some kind of backward compatibility, an action written in uppercase letters that leads to an empty result list, will be ignored.\nIn this case the list of selected zettel is returned.\n\n=== HTTP Status codes\n; ''200''\n: Query was successful.\n; ''204''\n: Query was successful, but results in no content.\n Most likely, you specified no appropriate aggregator.\n; ''302''\n: Query was successful, redirect to first zettel in list.\n; ''400''\n: Request was not valid.\n There are several reasons for this.\n Maybe the access bearer token was not valid, or you forgot to specify a valid query."))