API

If you ever need to add registrations or serial numbers programmatically, there is an API for it.

All endpoints are available at https://product-reg.varify.xyz/api/

Generate Access Token

Access token can be obtain in the Shopify Admin > Apps > My Product Registration > Settings > General > API Access token > Generate

Usage

Authentication

Requests to api endpoints needs an authentication header with the access token, setting the following in the request header e.g

Authorization: Bearer [access-token]

The access token can either put in the Authorization header or in the body, but put the access token in the header is preferred

Registrations - add new (POST)

Once the access token is generated, it can be use to register a new product

  1. Make an HTTP POST request to the endpoint - https://product-reg.varify.xyz/api/registrations

  2. The POST request should have the following JSON payload

{
    "accessToken": "12323213123",
    "registrations": [
        {
            "productName": "MacBook 2018",
            "customerEmail": "tom@example.com",
            "customerName": "Tom Delong",
            "serialNumbers": [
                "123",
                "321"
            ],
            "purchaseDate": "2019-01-01",
            "greetings": "hello world!",
        }
    ]
}

Or customer data and address can be added in the payload

{
  "registrations": [
    {
      "productName": "MacBook 2018",
      "customerEmail": "tom@example.com",
      "serialNumbers": [
        "123",
        "321"
      ],
      "purchaseDate": "2019-01-01",
      "greetings": "hello world!",
      "customer": {
        "id": 123,
        "firstName": "Testy",
        "lastName": "Test",
        "address1": "1 highstreet",
        "address2": "",
        "city": "New York",
        "State": "New York",
        "country": "US",
        "postCode": "1234567",
        "phone": "1234567"
      }
    }
  ]
}

It's possible to register multiple products in one call - simply add another registration object to the registrations array.

If need to add data to different form e.g not the default product-registration, a new key will needed add to the registration "type": "form-slug-name", then form slug name can be found in the Form > View on frontend

If there are extra fields just add those field as key within registration, the key name can be found in the form's design and field options

Registrations - Modify existing registration (PUT)

Once the access token is generated, it can be used to modify existing registration (the registration id can be found in the admin or via the webhook payload)

  1. Make a HTTP PUT request to the endpoint - https://product-reg.varify.xyz/api/registrations/:regId

  2. The PUT request should have the following JSON payload

{
    "accessToken": "12323213123",
    "registration": {
            "productName": "MacBook 2018",
            "customerEmail": "tom@example.com",
            "customerName": "Tom Delong",
            "serialNumbers": [
                "123",
                "321"
            ],
            "purchaseDate": "2019-01-01",
            "fields": {
                "greetings": "hello agaiin",
            }
    }
}

If there are extra fields need to update, then put it under fields key

Delete registration (DELETE)

A registration id is needed to delete a registration

  1. make a HTTP DELETE request to the endpoint /api/registrations/:regId

  2. It will return 200 if its all good, otherwise throw error with message

Registrations (GET) - Get customer's registrations

  1. make a HTTP GET request to the endpoint /api/registrations?email=tom@example.com, the email must be in the query string

  2. It will return all customer's registrations

Available query strings

  • email - Only get registrations belong to specific email e.g /api/registrations?email=tom@example.com

  • customerId - Only get registrations belong to specific customer id (shopify customer id) e.g /api/registrations?customerId=88888888

  • formSlug - Only get registration within specific form

  • limit - Limit the results

Serial Numbers

Here is example the payload for adding serial numbers (POST)

  1. Make a HTTP POST request to the endpoint /api/serial_numbers

  2. The POST request should have the following JSON payload

{
    "accessToken": "12323213123",
    "serialNumbers": [
        {
            "serialNumber": "22018",
            "sku": "mac123",
            "customerTags": "VIP,mac",
        }
    }

The customerTags is a comma-separated of tags you want to tag the customer who register this serial number

Get a unused/unregistered serial number (GET)

You can get a random unregistered serial number

  1. Make a HTTP GET request to the endpoint /api/serial_number

  2. It will return a random unregistered serial number if there is one with status 200

  3. If there is no unregistered seiral number, it wil return 204

Get serial numbers (GET)

Getting information of a serial numbers

  1. make a HTTP GET request to the endpoint /api/serial_numbers

  2. It will return the serial numbers

Get a serial number (GET)

Getting information of a serial number

  1. make a HTTP GET request to the endpoint /api/serial_numbers/test123, test123 is a serial number

  2. It will return the serial number info if there is one

  3. if there is no such serial number, it will return 204

Upload a file/asset/receipt

Its possible to upload a file and then use the URL as the receipt, the upload process is divided into two parts

  1. Get a presigned URL from the app server

Here is the steps

  1. Make a HTTP GET request to the endpoint /api/upload_fiile with the query string fileType, fileName and fileSize, e.g /api/upload_file?fileName=test.png&fileType=image/png&fileSize=123

  2. Then it will return a signedRequest url which you can use it to upload file, the url is the final url of the file

  3. Make a HTTP PUT request to the signedRequest url and put the file in the payload e.g

    curl -X PUT -T "/path/to/file" "presigned URL"

Here are some examples of how to upload it in Javascript

// Upload the file in nodejs
let blobData = new Blob([new Uint8Array(array)], {type: 'image/jpeg'})
const result = await fetch(signedRequestURL, {
  method: 'PUT',
  body: blobData
})

// Upload the file in browser
// file - is the file object of the html input type=file
const result = await fetch(signedRequestURL, {
  method: 'PUT',
  body: file
})

Last updated