kushy / metrc-php-sdk
An easy to use PHP API for the METRC state licensed seed to sale cannabis API using the Guzzle library. Require, create new instance with API keys, and query any endpoint (GET, POST, PUT, DELETE)
Requires
- guzzlehttp/guzzle: ^6.3
This package is not auto-updated.
Last update: 2024-09-23 13:31:46 UTC
README
Dependencies
Development
Quick Start Guide + API Keys
- Install the METRC package with Composer:
composer require 'kushy/metrc-php-sdk'
- Require whichever route class you need in your application - in this case we want to access the
/harvests/
endpoint (assuming you're using PSR-4):
require_once '../../../vendor/autoload.php'; use Kushy\Metrc\Routes\Harvests;
- Create a new instance of the route class (
Harvests
) and pass through your state's abbreviated name (in this caseca
for California) and Vendor + User API keys:
$harvests = new Harvests('ca', $vendorApiKey, $userApiKey);
- Use one of the class methods to query the API - this example grabs the active harvests:
$harvests = $metrc->getActive($licenseNumber, $startDate, $endDate);
Tips
General
- General API Tips
- All API requests (POST/PUT) must be sent in JSON format (see Guzzle on JSON)
- All dates are ISO 8601 format. See below for time conversion snippets.
Dates are ISO format
Sending dates to API? Use ISO 8601 formatted date: 0001-01-01T00:00:00+00:00
$lastModifiedStart = date('c', strtotime($startDate));
Quickly get object keys Copy API response/sample data and do this:
/** * REGEX for * (["'])(?:(?=(\\?))\2.)*?\1: * ALT+ENTER to select all found objects * Paste * Find and replace ": with nothing * Find and replace " with $sample-> **/ "Id": 1, "Name": "2014-11-19-Harvest Room-M", "HarvestType": "Product", "DryingRoomId": 1, "DryingRoomName": "Harvest Room", "CurrentWeight": 0.0, "TotalWasteWeight": 0.0, "PlantCount": 70, "TotalWetWeight": 40.0, "PackageCount": 5, "TotalPackagedWeight": 0.0, "UnitOfWeightName": "Ounces", "LabTestingState": null, "LabTestingStateDate": null, "IsOnHold": false, "HarvestStartDate": "2014-11-19", "FinishedDate": null, "ArchivedDate": null, "LastModified": "0001-01-01T00:00:00+00:00", "Strains": []
Testing
Example files are provided in the package for each endpoint and method (GET, POST, PUT, DELETE) to easily test each endpoint manually with properly formed sample data.
For example, to see a list of all active harvests, copy the code from
test/example/harvests/get-active-harvest.php
.
I'm looking to implement unit testing soon to ensure package integrity.