Search¶
The /v2/search endpoint provides a single text-search entry point across the most commonly searched Metrc collections. Hand it a tag, a manifest number, an item name, or a partial label, and it returns a ranked list of every matching object across the relevant Metrc collections, without you having to know which collection to look in.
A T3+ subscription is not required to use this endpoint.
flowchart LR
Q["query=1A4FF01..."] --> D["Detected format:<br/>HEX_STRING"]
D --> C["Every collection with a field<br/>that holds that kind of value"]
D -.-> SK(["Other collections:<br/>skipped, reason format"])
C --> R["One list,<br/>sorted by score"] How a Search Works¶
- The query's format decides where it is looked for. The query is classified as one or more of
DATETIME,HEX_STRING,INTEGERandBASIC_STRING;"12345"is bothINTEGERandHEX_STRING. Each field is searched only for the formats it can hold, so"Blue Dream"(BASIC_STRING) skips the tag and sales receipt collections. A skipped collection is reported inendpointsasskippedwith reasonformat. - The default set covers tiers 1 and 2, the 17 most-used collections. Pass
tiersto choose how deep to search, ort3EndpointIdsto search exactly the collections you name. See Choosing What to Search. Each collection is named by the T3 endpoint id of its list endpoint:METRC_ACTIVE_PACKAGESfor/v2/packages/active. - Each collection returns up to
pageSizematches (default 10, max 100). A partial tag or number ranks values that end with it first, so0042finds labels ending in0042before labels that merely contain it. A complete 24-character tag is matched exactly, along with the packages made from it (sourcePackageLabels). - Results come back as one list. Each match is scored on every field it was searched on, its
scoreis the best of them, and the list is sorted byscoredescending. See Tuning Search Results.
Query Formats¶
Format detection determines which endpoints are eligible. The detection is greedy; a single query can satisfy multiple formats simultaneously, in which case it unlocks the union of their endpoints.
| Format | Detection rule | Example |
|---|---|---|
DATETIME | ISO 8601 date or datetime: ^\d{4}-\d{2}-\d{2}(T...)?$ | 2024-07-17 |
HEX_STRING | Only hex characters (0-9a-fA-F), with at least one digit | 1A4FF0100000022000000123, 0042, B52 |
INTEGER | Only digits | 12345 |
BASIC_STRING | Anything that is neither only digits nor tag-like. A hex query is tag-like when it starts with 1A or is 8 or more characters long | Blue Dream, ACDC, B52 |
A word that happens to be hex, such as ACDC or Cafe, has no digit, so it is searched as a name. A short hex query with a digit, such as B52, could be the end of a tag or a strain name, so it is both HEX_STRING and BASIC_STRING.
Note
No endpoint searches date fields. A pure DATETIME query (e.g. 2024-07-17) is rejected with a 400. Use a tag, label, manifest number, or name instead.
Endpoint Catalog¶
The 39 endpoints /search can query, by T3 endpoint id, with the kind of object each holds, its tier, and the fields it searches. Tag fields (label, packageLabel, sourcePackageLabels) are searched for HEX_STRING and INTEGER queries, number fields (manifestNumber, receiptNumber, batchNumber, number) for INTEGER queries, code fields (productionBatchNumber and the tag order numbers) for every query except a complete 24-character tag, and name fields for BASIC_STRING queries.
| T3 endpoint id | Object type | Tier | Tag, number or code fields | Name fields |
|---|---|---|---|---|
METRC_ACTIVE_PACKAGES | PACKAGE | 1 | label, sourcePackageLabels, productionBatchNumber | item.name, item.strainName, sourceHarvestNames, locationName, item.productCategoryName |
METRC_INTRANSIT_PACKAGES | PACKAGE | 2 | label, sourcePackageLabels, productionBatchNumber | item.name, item.strainName, sourceHarvestNames, locationName, item.productCategoryName |
METRC_ONHOLD_PACKAGES | PACKAGE | 3 | label, sourcePackageLabels, productionBatchNumber | item.name, item.strainName, sourceHarvestNames, locationName, item.productCategoryName |
METRC_INACTIVE_PACKAGES | PACKAGE | 3 | label, sourcePackageLabels, productionBatchNumber | item.name, item.strainName, sourceHarvestNames, locationName, item.productCategoryName |
METRC_TRANSFERRED_PACKAGES | PACKAGE | 2 | packageLabel, sourcePackageLabels | productName, itemStrainName, sourceHarvestNames, productCategoryName |
METRC_LAB_SAMPLE_PACKAGES | PACKAGE | 3 | label, sourcePackageLabels, productionBatchNumber | item.name, item.strainName, sourceHarvestNames, locationName, item.productCategoryName |
METRC_VEGETATIVE_PLANTS | PLANT | 1 | label | strainName, locationName |
METRC_FLOWERING_PLANTS | PLANT | 1 | label | strainName, locationName |
METRC_ONHOLD_PLANTS | PLANT | 3 | label | strainName, locationName |
METRC_INACTIVE_PLANTS | PLANT | 3 | label | strainName, locationName |
METRC_ACTIVE_MOTHER_PLANTS | PLANT | 2 | label | strainName, locationName |
METRC_ONHOLD_MOTHER_PLANTS | PLANT | 3 | label | strainName, locationName |
METRC_INACTIVE_MOTHER_PLANTS | PLANT | 3 | label | strainName, locationName |
METRC_ACTIVE_PLANTBATCHES | PLANT_BATCH | 1 | name, strainName, locationName | |
METRC_ONHOLD_PLANTBATCHES | PLANT_BATCH | 3 | name, strainName, locationName | |
METRC_INACTIVE_PLANTBATCHES | PLANT_BATCH | 3 | name, strainName, locationName | |
METRC_ACTIVE_HARVESTS | HARVEST | 1 | name | |
METRC_ONHOLD_HARVESTS | HARVEST | 3 | name | |
METRC_INACTIVE_HARVESTS | HARVEST | 3 | name | |
METRC_HARVEST_SCHEDULES | HARVEST_SCHEDULE | 3 | batchNumber | locationName |
METRC_INCOMING_ACTIVE_TRANSFERS | TRANSFER | 2 | manifestNumber | shipperFacilityInfo |
METRC_INCOMING_INACTIVE_TRANSFERS | TRANSFER | 3 | manifestNumber | shipperFacilityInfo |
METRC_OUTGOING_ACTIVE_TRANSFERS | TRANSFER | 2 | manifestNumber | deliveryFacilities |
METRC_OUTGOING_REJECTED_TRANSFERS | TRANSFER | 2 | manifestNumber | deliveryFacilities |
METRC_OUTGOING_INACTIVE_TRANSFERS | TRANSFER | 3 | manifestNumber | deliveryFacilities |
METRC_HUB_TRANSFERS | TRANSFER | 3 | manifestNumber | |
METRC_TRANSFER_TEMPLATES | TRANSFER_TEMPLATE | 3 | name, deliveryFacilities | |
METRC_ACTIVE_SALES | SALES_RECEIPT | 2 | receiptNumber | |
METRC_INACTIVE_SALES | SALES_RECEIPT | 3 | receiptNumber | |
METRC_ACTIVE_PROCESSING_JOBS | PROCESSING_JOB | 3 | number | name, jobTypeName |
METRC_INACTIVE_PROCESSING_JOBS | PROCESSING_JOB | 3 | number | name, jobTypeName |
METRC_ACTIVE_ITEMS | ITEM | 1 | name, strainName | |
METRC_ACTIVE_STRAINS | STRAIN | 2 | name | |
METRC_ACTIVE_LOCATIONS | LOCATION | 2 | name | |
METRC_AVAILABLE_TAGS | TAG | 2 | label | |
METRC_USED_TAGS | TAG | 2 | label | |
METRC_VOIDED_TAGS | TAG | 3 | label | |
METRC_CURRENT_TAG_ORDERS | TAG_ORDER | 3 | orderNumber, trackingNumber, purchaseOrderNumber | |
METRC_HISTORY_TAG_ORDERS | TAG_ORDER | 3 | orderNumber, trackingNumber, purchaseOrderNumber |
METRC_HUB_TRANSFERS is in tier 3 because a license that both ships and transports would otherwise get the same manifest twice. METRC_LAB_SAMPLE_PACKAGES returns one result per lab test, so a package with several tests appears once for each.
Choosing What to Search¶
Tier 1 holds the collections most searches are answered by, tier 2 the remaining active collections and transferred packages, and tier 3 on-hold, inactive and the rest. Choose how deep to search with tiers, or name exact collections with t3EndpointIds:
| Request | Searches |
|---|---|
| Neither | Tiers 1 and 2, 17 collections |
tiers=1 | Tier 1: active packages, vegetative and flowering plants, active plant batches, active harvests, items |
tiers=3 | Tier 3 only |
tiers=1,2,3 | All 39 collections |
t3EndpointIds=METRC_ACTIVE_PACKAGES,METRC_INACTIVE_PACKAGES | Exactly those two |
Every collection selected is searched. Sending both tiers and t3EndpointIds is a 400. Every result and every entry in endpoints carries its tier and objectType, so results can be grouped by kind of object whatever their state:
import requests
response = requests.get(
"https://api.trackandtrace.tools/v2/search",
params={"licenseNumber": "LIC-00001", "query": "0000123", "tiers": "1,2,3"},
headers={"Authorization": "Bearer <TOKEN>"},
)
for match in response.json()["data"]:
print(match["objectType"], match["tier"], match["t3EndpointId"], match["score"])
Searching Several Licenses¶
Repeat licenseNumber to search several licenses in one request. Every collection is searched on every license:
import requests
response = requests.get(
"https://api.trackandtrace.tools/v2/search",
params={
"licenseNumber": ["LIC-00001", "LIC-00002"],
"query": "1A4FF0100000022000000123",
},
headers={"Authorization": "Bearer <TOKEN>"},
)
for match in response.json()["data"]:
print(match["licenseNumber"], match["t3EndpointId"], match["score"])
- Every result and every entry in
endpointscarries itslicenseNumber. endpointslists the licenses in the order you named them, and that order breaks ties between equal scores.- A comma-joined value (
licenseNumber=LIC-00001,LIC-00002) is a400, and so is naming the same license twice. - A search covers at most 60 license and collection pairs: licenses times the collections searched on each. Three licenses fit the 17 default collections. To search more licenses, name fewer collections with
t3EndpointIds: ten licenses fit six collections.
Validation Rules¶
/search rejects requests that can't produce useful results, with a 400 Bad Request. The most common rejections:
- Empty
query(or whitespace-only). Provide a real query string. - Pure ISO 8601 date/datetime
query(e.g.2024-07-17,2024-07-17T20:26:07): no endpoint searches date fields, so the request would silently return empty. Use a tag, label, manifest number, or name instead. - Unknown
t3EndpointIds: the error message names the specific unrecognized IDs (not the whole list you sent) and says why each was refused. A supercollection id, such asMETRC_ACTIVE_SUPERPACKAGES, names the collection to search instead. Empty entries, such as the one a trailing comma leaves, are ignored. - A
tiersvalue other than1,2or3, or bothtiersandt3EndpointIds. - Out-of-range
pageSize: must be an integer in[1, 100]. minScore: it was removed. Every match is returned, best first.- A repeated or comma-joined
licenseNumber: name each license once, repeating the parameter. - More than 60 license and collection pairs: the error gives the count. Name fewer licenses, or fewer collections with
t3EndpointIds.
Response Shape¶
Every successful response has the same four top-level keys.
{
"data": [
{
"t3EndpointId": "METRC_ACTIVE_PACKAGES",
"licenseNumber": "LIC-00001",
"tier": 1,
"objectType": "PACKAGE",
"score": 1.0,
"isExactMatch": true,
"matchedFields": [{ "field": "label", "score": 1.0, "matchType": "EXACT" }],
"matchedEntry": { "...": "..." }
},
{
"t3EndpointId": "METRC_USED_TAGS",
"licenseNumber": "LIC-00001",
"tier": 2,
"objectType": "TAG",
"score": 0.9,
"isExactMatch": true,
"matchedFields": [{ "field": "label", "score": 0.9, "matchType": "EXACT" }],
"matchedEntry": { "...": "..." }
}
],
"endpoints": [
{ "t3EndpointId": "METRC_ACTIVE_PACKAGES", "licenseNumber": "LIC-00001", "tier": 1, "objectType": "PACKAGE", "status": "answered", "reason": null, "metrcStatusCode": null, "resultCount": 1, "truncated": false, "totalAvailable": 1 },
{ "t3EndpointId": "METRC_INTRANSIT_PACKAGES", "licenseNumber": "LIC-00001", "tier": 2, "objectType": "PACKAGE", "status": "failed", "reason": "timeout", "metrcStatusCode": null, "resultCount": 0, "truncated": false, "totalAvailable": null },
{ "t3EndpointId": "METRC_USED_TAGS", "licenseNumber": "LIC-00001", "tier": 2, "objectType": "TAG", "status": "answered", "reason": null, "metrcStatusCode": null, "resultCount": 1, "truncated": false, "totalAvailable": 1 },
{ "t3EndpointId": "METRC_ACTIVE_ITEMS", "licenseNumber": "LIC-00001", "tier": 1, "objectType": "ITEM", "status": "skipped", "reason": "format", "metrcStatusCode": null, "resultCount": 0, "truncated": false, "totalAvailable": null }
],
"detectedQueryFormats": ["HEX_STRING"],
"request": {
"query": "1A4FF0100000022000000123",
"licenseNumber": "LIC-00001",
"licenseNumbers": ["LIC-00001"],
"pageSize": 10,
"t3EndpointIds": ["METRC_ACTIVE_PACKAGES", "METRC_INTRANSIT_PACKAGES", "METRC_USED_TAGS", "METRC_ACTIVE_ITEMS"],
"tiers": null
}
}
data¶
Every result, sorted by score descending. Equal scores follow the order you named the licenses in, then the catalog order above, so a package comes before the used tag with the same label. The shape of matchedEntry depends on t3EndpointId: a match from METRC_ACTIVE_PACKAGES is a Metrc package, a match from METRC_INCOMING_ACTIVE_TRANSFERS is a Metrc transfer.
| Field | Meaning |
|---|---|
tier | The tier of the collection the result came from: 1, 2 or 3. |
objectType | The kind of object, whatever its state: PACKAGE for active, inactive and on-hold packages alike. See the catalog above. |
score | In [0, 1]. The best score among the fields that matched, times 0.9 outside tier 1. |
isExactMatch | The result's own identifier (its tag, its manifest, receipt, batch or order number, or its name) equals the query, ignoring case. Zero padding counts: 123456 is not manifest 0000123456. |
matchedFields | Every field that matched, highest score first, each with its score and matchType (EXACT, PREFIX, SUFFIX or PARTIAL). Use it to highlight the match. See Scores. |
endpoints¶
Every endpoint the request covered, with how it ended: license by license in the order you named them, and in catalog order within each.
status | Meaning |
|---|---|
answered | Metrc answered. Its results are in data. |
skipped | Not sent. reason says why. |
failed | Sent but not answered. reason says why. |
reason | Meaning |
|---|---|
format | The query's format fits none of the endpoint's fields. |
forbidden | The account cannot read this collection on this license. When T3 already knows this, the endpoint is skipped rather than failed. |
timeout | Metrc did not answer in time. |
metrc_error | Metrc answered with an error, or could not be reached. metrcStatusCode has Metrc's status when it answered. |
session | The Metrc session expired. Authenticate again. |
internal | The server failed to handle Metrc's answer. |
truncated is true when Metrc had more matches than pageSize returned, and totalAvailable is Metrc's count. Raise pageSize or narrow the query to see the rest.
request Echo¶
The request object echoes the resolved request: values after defaults and trimming, and t3EndpointIds as the full set covered, whether named or default. licenseNumbers lists every license searched, in order; licenseNumber is the first of them. tiers is the tiers searched, [1, 2] when you named neither tiers nor ids, and null when you named t3EndpointIds. Useful for matching responses to requests when a client runs several searches at once.
Errors¶
Errors are RFC 7807 problem details, with title, status, detail and a machine-readable code. Besides the 400s above:
401withcode: METRC_SESSION_EXPIRED: the Metrc session expired during the search. Authenticate again and retry.403withcode: FORBIDDEN: alicenseNumberis not one of your session's licenses. The error names every such license.429withcode: RATE_LIMIT_EXCEEDED: search has its own budget per Metrc user, separate from the limit your other requests share. It is counted in license and collection pairs, 5,000 a minute by default: one license at the 17 default collections costs 17, three licenses cost 51. The error says what this search would have cost.
Examples¶
Substitute your API token (Authorization: Bearer ...) and license number into each example.
Python, list where a tag appears:
import requests
response = requests.get(
"https://api.trackandtrace.tools/v2/search",
params={"licenseNumber": "LIC-00001", "query": "1A4FF0100000022000000123"},
headers={"Authorization": "Bearer <TOKEN>"},
)
body = response.json()
for match in body["data"]:
print(match["t3EndpointId"], match["score"], match["isExactMatch"])
for endpoint in body["endpoints"]:
if endpoint["status"] == "failed":
print("not searched:", endpoint["t3EndpointId"], endpoint["reason"])
Tag scan, find every collection a tag appears in:
curl 'https://api.trackandtrace.tools/v2/search?licenseNumber=LIC-00001&query=1A4FF0100000022000000123' \
-H 'Authorization: Bearer <TOKEN>'
Manifest number lookup, find a transfer by its manifest number:
curl 'https://api.trackandtrace.tools/v2/search?licenseNumber=LIC-00001&query=1234566' \
-H 'Authorization: Bearer <TOKEN>'
This query is detected as HEX_STRING and INTEGER, so it searches every endpoint in the default tiers that accepts either: packages, plants, tags, transfers, and so on.
Item or strain name search, narrowed to items and strains for speed:
curl 'https://api.trackandtrace.tools/v2/search?licenseNumber=LIC-00001&query=Blue%20Dream&t3EndpointIds=METRC_ACTIVE_ITEMS,METRC_ACTIVE_STRAINS' \
-H 'Authorization: Bearer <TOKEN>'
Include inactive packages in a label search:
curl 'https://api.trackandtrace.tools/v2/search?licenseNumber=LIC-00001&query=0000123&t3EndpointIds=METRC_ACTIVE_PACKAGES,METRC_INTRANSIT_PACKAGES,METRC_INACTIVE_PACKAGES' \
-H 'Authorization: Bearer <TOKEN>'
Next Steps¶
- Control result volume and stream results with Tuning Search Results.
- Load a full record once you have found it, by the id
/searchreturned: Loading One Record by ID. - Load full records in bulk: Supercollections.
- Check what your account may query with Permissions.
- Example script:
basics/search.py(search one or more licenses and save the hits).