developer portal

developer portal

  • Browse Docs
  • Build With Scantrust
  • Release Notes

›Consumer REST API

Consumer REST API

  • Getting Started
  • Installation
  • API Reference
  • 3rd Party Landing Page
  • Proxing or Self-hosting

Admin REST API

  • Getting Started
  • Authentication & Tokens
  • Network Access
  • Product API

    • Upload Products
    • Download Products

    Workorder API

    • Generating Work Orders
    • Download Work Orders

    SCM Data API

    • Synchronous vs. Asynchronous Uploads
    • Upload SCM Data (SYNC)
    • Upload SCM Data (ASYNC)
    • Special SCM Fields

    Code Download API

    • Download Code Data
    • Code Data Fields Glossary

    Scan Data API

    • Download Scan Data
    • Scan Data Fields Glossary

    Samples

    • Overview
    • Python
    • C#
    • JavaScript

3rd Party Landing Page

This page contains an example to add the following functionality to a 3rd party landing page:

  • Prompt user to share location
  • Update scan location to user's location

The scan ID will usually be passed as a query parameter in the URL like this:

https://some-website-url.com?scan_id=90ee96a4-f7ef-46fb-a3d9-181f66ae590d

To obtain your api-key:

portal > campaign > setttings > redirect

access_key

index.html

<html>
  <head>
    <script src="./scantrust_stc_sdk.js" type="text/javascript"></script>
    <script src="./script.js" type="text/javascript"></script>
  </head>
  <body></body>
</html>

scantrust_stc_sdk.js

function ScanTrustConsumerSDK (apiKey) {
  var apiKey = apiKey
  var scanId = ''

  // User accepted to share his position and a GPS location was retrieved
  // The pos object contains the position coordinates.
  // pos.coords.lat -> Latitude
  // pos.coords.lng -> Longitude
  var success = function (pos) {
    fetch("https://api.scantrust.com/api/v2/consumer/scan/<uuid>/geotag/", {
      method: "POST",
      mode: "cors",
      headers: {
        "Content-Type": "application/json",
        "X-ScanTrust-Consumer-Api-Key": apiKey
      },
      body: JSON.stringify({
        lat: pos.coords.latitude,
        lng: pos.coords.longitude
      })
    })
      .then(function (response) {
        if (response.ok) {
          return response
        } else {
          throw new Error()
        }
      })
      .then(function () {
        console.log('Scantrust Consumer SDK: Scan Location successfully updated')
      })
      .catch(function (err) {
        console.error("Scantrust Consumer SDK Error: " + err)
      })

  };

  // User didn't accept to share his position or the browser was unable to retrieve a GPS location
  // Reason for failure is inside the positionError object.
  // positionError.code == 1 PERMISSION_DENIED, The acquisition of the geolocation information failed because the page didn't have the permission to do it.
  // positionError.code == 2 POSITION_UNAVAILABLE The acquisition of the geolocation failed because at least one internal source of position returned an internal error.
  // positionError.code == 3 TIMEOUT The time allowed to acquire the geolocation, defined by positionOptions.timeout information was reached before the information was obtained.
  var error = function (positionError) {
    console.log("Scantrust Consumer SDK : Can't retrieve position. Code: " + positionError.code + ' message: ' + positionError.message)
  };

  this.updateScanLocation = function (id) {
    if (!id) {
      console.error('Scantrust Consumer SDK Error: Scan ID Not provided')
      return
    }

    scanId = id

    var positionOptions = {
      enableHighAccuracy: false,
      timeout: 5000
    }

    navigator.geolocation.getCurrentPosition(success, error, positionOptions)
  }
}

script.js

var API_KEY = "replace-with-you-api-key"
// The scan ID will usually be passed as a query parameter in the URL. Example: https://some-website-url.com?scan_id=90ee96a4-f7ef-46fb-a3d9-181f66ae590d
var scanId = "90ee96a4-f7ef-44fb-a3d9-181f62ae590d"

var sdk = new ScanTrustConsumerSDK(API_KEY)
sdk.updateScanLocation(scanId)
Last updated on 3/29/2021
← API ReferenceProxing or Self-hosting →
  • index.html
  • scantrust_stc_sdk.js
  • script.js
developer portal
Developer Docs
Mobile SDK (Android / iOS)API - Scantrust Consumer (STC)API - SmartLabelAPI - Product & SCM Data
Tools & Utilities
QR Generator (Win/Mac/Linux)Inline QA System (Win)SCM UploaderSystem StatusCompatible Phone List
Community
LinkedInRelease Notes (latest versions)GitHub
Copyright © 2021 Scantrust