Skip to navigation

Authentication

Access control for Ordergroove's REST APIs
View as Markdown

Ordergroove API Authentication is the access control system developers use to authorize requests to Ordergroove’s REST APIs over HTTPS. It supports two scopes: Application API Scope, which uses an x-api-key header for server-to-server calls (up to 10 keys per merchant, optionally with Bulk Operations permission), and Storefront API Scope, which lets a customer’s browser make calls scoped to that one customer with an HMAC-SHA256 signature your server generates, with optional Trust Level support for recognized-but-not-logged-in users. Both kinds of key are secrets that stay on your servers.

Keep your API keys secret

Application API keys and the Storefront API key are both secrets. Store them only on your servers, for example in environment variables or a secrets manager. Never put them in theme files, JavaScript that’s sent to the browser, mobile apps, or source control.

“Storefront” describes where signed requests come from, not where the key can go. Anyone who has your Storefront API key can generate a valid signature for any of your customers and call the API as that customer.


API Scope

Ordergroove’s APIs support two versions of authentication:

Application API Scope - Authentication via an x-api-key header that uses one of 10 keys available for your store. Use these keys (up to 10 per merchant) only for server-to-server requests, and never expose them on the client side.

  • Within Application API Scope, some keys may be granted the permission for “Bulk Operations”. This means the key will be able to return records across multiple customers when using the List endpoints. Without this permission, the key will only return records within the scope of a single customer.

Storefront API Scope - Authentication via a generated signature to call Ordergroove’s APIs straight from the client within the context of a single customer. Your server generates the signature with the Storefront API key, and only the signature is sent to the client. Never expose the key itself on the client side.

  • Within Storefront API Scope, you can optionally use Trust Level Authentication for customers who are in a recognized state but not fully logged into your site. This limits the given signature to a small subset of available actions and requires a different signature generation process.

Application API Scope

All requests use HTTP Basic Auth and must be made over HTTPS. Calls made over plain HTTP and calls without authentication will fail.

Keep your Application API keys secure, and share them only with people you trust.

Here is an example built in JavaScript:

const url = "https://restapi.ordergroove.com/subscriptions/";
const headers = {
"x-api-key": "<REPLACE_ME_WITH_APPLICATION_API_KEY>",
};
const queryString = new URLSearchParams({
customer: "<REPLACE_ME_WITH_CUSTOMER_ID>",
});
// Make the GET request with fetch
fetch(`${url}?${queryString}`, { headers: headers })
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
console.log(data); // Logs the data received from the API
})
.catch((error) => {
console.error("Error:", error);
});

Storefront API Scope

All requests use HTTP Basic Auth and must be made over HTTPS. Calls made over plain HTTP and calls without authentication will fail.

Never expose the Storefront API key

Your server, where the key is stored, generates the signature for the customer and passes only the result to the browser, which uses it to call Ordergroove’s APIs.

Standard Customer Authentication

For fully authenticated customers, generate the header value on your server. This example uses Node.js:

// Run this on your server, never in the browser.
const { createHmac } = require("node:crypto");
const MERCHANT_ID = "<REPLACE_ME_WITH_MERCHANT_ID>";
// Load the key from an environment variable or secrets manager. Don't hard-code it.
const STOREFRONT_API_KEY = process.env.OG_STOREFRONT_API_KEY;
// This function generates the OG Authorization header for a fully authenticated customer
function generateOGAuthorization(customerId) {
const ts = Math.floor(Date.now() / 1000);
// Sign "customer_id|timestamp" with HMAC-SHA256 and Base64-encode the result
const sig = createHmac("sha256", STOREFRONT_API_KEY)
.update(`${customerId}|${ts}`)
.digest("base64");
return JSON.stringify({
public_id: MERCHANT_ID,
sig_field: customerId,
ts,
sig,
});
}

Using Trust Level (Optional)

If your site can recognize a customer but the customer isn’t fully logged in, you can still authenticate limited actions by providing a trust_level field in the authorization header.

{
"public_id": "merchant_id",
"ts": "timestamp",
"sig_field": "customer_id",
"sig": "HMAC_signature",
"trust_level": "recognized"
}

If you include a trust_level, you must update the string used to generate the signature.

Signature Generation

On your server, use HMAC-SHA256 to sign a string with your Storefront API key. The string format depends on whether you’re using trust level:

  • Without trust level: customer_id|timestamp
  • With trust level: customer_id|trust_level|timestamp

Example in JavaScript (Node.js, on your server):

const { createHmac } = require("node:crypto");
const baseString = `${customerId}|recognized|${timestamp}`; // Include trust_level if used
const key = process.env.OG_STOREFRONT_API_KEY; // Never hard-code the key or send it to the browser
const signature = createHmac("sha256", key).update(baseString).digest("base64"); // HMAC-SHA256, Base64 encoded

This signature is valid for 2 hours.


Key Retrieval and Sample Code

Your store’s keys are on the API Keys page in RC3, at rc3.ordergroove.com/keys, along with code snippets in additional languages. The Application tab lists your Application API keys, and the Storefront tab shows your merchant ID and Storefront API key. To see or create keys, your RC3 user needs API key access. Without it, the keys are masked and Create is unavailable, so request access from your RC3 admin.

Treat both kinds of key like passwords. Don’t paste them into support tickets, chat, or email, and don’t commit them to source control. If an Application API key is exposed, create a replacement, move your integrations to it, and then disable the exposed key.

Generating an API key

  1. Log in to RC3 and select Developers > API Keys.
  2. On the Application tab, click Create.
  3. Enter an API Key Name that identifies where the key will be used, and an Email.
  4. Under Permissions, choose Read Only or Read and Write.
  5. Turn on Allow bulk queries? only if the key needs the Bulk Operations permission described in API Scope, which lets it return records across multiple customers.
  6. Agree to the terms and conditions, and click Save.
  7. Copy the new key from the API key column and share it with your developers through a secure channel, such as a password manager. Send it in the x-api-key header of each server-side request.

Modifying API key permissions

  1. Log in to RC3 and select Developers > API Keys.
  2. On the Application tab, find the key and open the three-dot menu at the end of its row.
  3. Select one of the following:
    • Edit to change the key’s Permissions or Allow bulk queries? setting, then click Save. A key’s name and email can’t be changed.
    • Disable to turn the key off. Type DISABLE to confirm.

Removing write access or bulk queries from a key that’s in use can break the integrations that rely on it, and so can disabling it. Make sure nothing still needs a key’s access before you change or disable it.