Skip to content

Instantly share code, notes, and snippets.

@noogen
Last active May 15, 2019 18:24
Show Gist options
  • Save noogen/e0fe7469de4631472d9bbff4b2b56391 to your computer and use it in GitHub Desktop.
Save noogen/e0fe7469de4631472d9bbff4b2b56391 to your computer and use it in GitHub Desktop.
API Doc

GTIN Image API

Example GTIN with valid check-digit: 00666522900091

You sent us an image without/0 as check-digit, simply request your image as: https://han.brickinc.net/gtin/00666522900090.jpg

Since it's a national product, pass in a valid check-digit to get Brick's image: https://han.brickinc.net/gtin/00666522900091.jpg

NOTE The free API will watermark your image and has a limit of 10 requests per minute, with a burst of 5 requests.

To use your paid API, no limit or watermark. Simply md5 sign the GTIN with expires time, and provide in the query string similar to our php example below:

    /**
     * @param  $baseUrl - non protected part of the URL including hostname, e.g. https://han.brickinc.net/gtin/
     * @param  $gtin    - the gtin
     * @param  $secret  - the shared secret
     * @param  $ttl     - the number of seconds until this link expires
     * @return string
     */
    function buildSecureLink($baseUrl, $gtin, $secret, $ttl)
    {
        $expires = time() + $ttl;
        $md5     = md5("$expires$gtin $secret", true);
        $md5     = base64_encode($md5);
        $md5     = strtr($md5, '+/', '-_');
        $md5     = str_replace('=', '', $md5);

        return $baseUrl . $gtin . '?md5=' . $md5 . '&expires=' . $expires;
    }

$baseUrl = 'https://han.brickinc.net/gtin/';
echo buildSecureLink($baseUrl, $gtin, $secret, $ttl);

Example output: https://han.brickinc.net/gtin/00666522900090.jpg?md5=9qlN2DscJIME4d8U4zAG5w&expires=1589494411

Please contact us to get your API secret for generating the md5 signature/query string.

Additionally, you can provide the width as w and height as h in the query string. Example: https://han.brickinc.net/gtin/00666522900090.jpg?md5=9qlN2DscJIME4d8U4zAG5w&expires=1589494411&w=300

When only width is provided, the image will resize to specified width, while height is resized proportionally. The system will perform a crop operation when both width and height are provided.

NOTE

Check-digit is required. You can pass in 0/anything if you do not know the check-digit. For national product, we will automatically calculate the check digit for you.

The API will also work for EAN-13 or EAN-12 as it will auto-append 0 to make a GTIN-14 lookup. Example: https://han.brickinc.net/gtin/666522900090.jpg

LEGACY REST API

Get image by UPC code or recipe file name

Path param: {size} - the image requested width (optional)

Querystring: q - the 10 digits UPC code (no check digit) or recipe image name

Example:

Get image by image id

Path param: {size} - the image requested width (optional)

Querystring: q - the image id

Example:

Get alternative images - response application/json

{
  "$id": "1",
  "Result": [
    {
      "$id": "2",
      "name": "894318",
      "alt": null,
      "meta1": null,
      "meta2": null
    },
    {
      "$id": "3",
      "name": "921860",
      "alt": null,
      "meta1": null,
      "meta2": null
    },
    {
      "$id": "4",
      "name": "931860",
      "alt": null,
      "meta1": null,
      "meta2": null
    }
  ]
}

Note: REST API also support callback query string for jsonp response.

Example: https://hannaford.gsnrecipes.com/api/v1/image/alts?q=4138010184&callback=hi

LEGACY WEBAPI

Get the JPEG image based on UPC code or file name

Querystring:

  1. vector - Blowfish encrypted (shared key) of parameters 2-5 below
  2. code - the 10 digits UPC code (no check digit) or recipe image name
  3. size - the image requested width
  4. min - the min size
  5. random - some random string (for cache management)
  6. name - the image id

Example:

Get alternate images for a product - return json with content type as "text/plain"

Querystring:

  1. code - the UPC code

Response - json array of alternative images

{ "Result": [ { "name": "894318", "alt": "", "meta1": "", "meta2": "" }, { "name": "921860", "alt": "", "meta1": "", "meta2": "" }, { "name": "931860", "alt": "", "meta1": "", "meta2": "" } ] }

Example:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment