2017 © Pedro Peláez
 

library 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)

image

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)

  • Saturday, June 23, 2018
  • by whoisryosuke
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Metrc API SDK

Dependencies

Development

Quick Start Guide + API Keys

  1. Install the METRC package with Composer: composer require 'kushy/metrc-php-sdk'
  2. 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;
  1. Create a new instance of the route class (Harvests) and pass through your state's abbreviated name (in this case ca for California) and Vendor + User API keys:
$harvests = new Harvests('ca', $vendorApiKey, $userApiKey);
  1. 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., (*1)

Dates are ISO format Sending dates to API? Use ISO 8601 formatted date: 0001-01-01T00:00:00+00:00, (*2)

$lastModifiedStart = date('c', strtotime($startDate));

Quickly get object keys Copy API response/sample data and do this:, (*3)

/**
 * 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., (*4)

For example, to see a list of all active harvests, copy the code from test/example/harvests/get-active-harvest.php., (*5)

I'm looking to implement unit testing soon to ensure package integrity., (*6)

The Versions

23/06 2018

dev-master

9999999-dev https://kushy.net/developers

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)

  Sources   Download

MIT

The Requires

 

api sdk marijuana metrc cannabis