Get an API key and product ID(s)

If you want to quickly try out the Corrily API, you can use the following demo API key and product IDs:

  • API key: b82fd0fa-2a1b-4226-b6c0-22884ae97f84
  • Product IDs:
    • monthly
    • annual

See Setup to learn how to create your own API key and product ID(s).

Notify Corrily of payment gateway events

You don’t need to integrate Corrily with your payment gateway(s) right now. You’ll need to do this before deploying Corrily to production, however.

As explained in Price optimization overview, Corrily needs to be notified of subscription and charge events. The easiest way is through OAuth and just requires 2 clicks. After access is granted, your payment gateway automatically notifies Corrily of subscription and charge events. Otherwise you can manually notify Corrily.

If you’re using Stripe and would like to get your Corrily integration started now, click the Connect with Stripe button to grant Corrily read-only access to your Stripe subscription and charge events.

Calculate a price

Run the following code samples to try out Corrily’s calculate price REST API endpoint. This is the endpoint that you call if you want to localize or optimize your prices; it handles both use cases. See Calculate price response for an explanation of the response object’s fields. The first time that you call the endpoint, it calculates a price for the user ID and IP address you specified. On subsequent calls (assuming that you pass in the same user ID and IP address as before) Corrily returns the same price data from the first call.

Note that the demo API key (api_key) and product IDs (products) are hardcoded into the code samples below.

An easy way to run the JavaScript code samples

A tip for anyone who is not familiar with frontend programming but would still like to try out the JavaScript code samples below: your browser’s console is essentially a REPL.

Another easy way to try out the API

Go to the calculate price reference page, enter the required fields, then click Try It.

Create a price based on the client’s IP address

In this first code sample, the get_ip_from_request field instructs Corrily to infer the user’s location from their IP address.

JavaScript
const headers = new Headers();
headers.append("api_key", "b82fd0fa-2a1b-4226-b6c0-22884ae97f84");
headers.append("Content-Type", "application/json");

// https://stackoverflow.com/a/2117523
function uuidv4() {
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
    (
      c ^
      (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
    ).toString(16)
  );
}

const data = JSON.stringify({
  user_id: uuidv4(),
  get_ip_from_request: true,
  products: ["monthly", "annual"],
});

const options = {
  method: "POST",
  headers: headers,
  body: data,
  redirect: "follow",
};

fetch("https://client.corrily.com/v1/prices", options)
  .then((response) => response.json())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

Create a price based on a country code

In this next example, the country field instructs Corrily to return a price in the specified country’s currency.

JavaScript
const headers = new Headers();
headers.append("api_key", "b82fd0fa-2a1b-4226-b6c0-22884ae97f84");
headers.append("Content-Type", "application/json");

// https://stackoverflow.com/a/2117523
function uuidv4() {
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
    (
      c ^
      (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
    ).toString(16)
  );
}

const data = JSON.stringify({
  user_id: uuidv4(),
  country: "JP",
  products: ["monthly", "annual"],
});

const options = {
  method: "POST",
  headers: headers,
  body: data,
  redirect: "follow",
};

fetch("https://client.corrily.com/v1/prices", options)
  .then((response) => response.json())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

Next steps