Documentation

Welcome to the Modern Pricing API! You can use our API to access Modern Pricing API endpoints, which can provide information regarding the visitors to your website and their ability to afford your goods and services.

Quick Links

Looking for a fast and easy integration? We recommend checking out our JavaScript snippet or our Segment integration.

Already completed your integration? Learn more about our conversion tracking installation.

Still exploring? We're glad you're here! Continue reading below...

Authentication

Modern Pricing uses API keys to allow access to the API. You can register a new Modern Pricing API key at https://modernpricing.com.

Modern Pricing expects for the API key to be included in all API requests to the server in a header that looks like the following:

Authorization: Basic your-api-key-goes-here

Note: You must replace your-api-key-goes-here with your personal API key.

curl -X GET https://modernpricing.com/v1/scores \
-H "Authorization: Basic your-api-key-goes-here" \
-H "Accept: application/json"

Scores

This endpoint calculates a score for a given set of characteristics set by your visitors.

HTTP Request

POST https://modernpricing.com/v1/scores

Query Parameters
Parameter Required Description
ip_address true The ip address of the visitor you want to score.
user_agent false The software client acting on behalf of the visitor.

curl -X POST https://modernpricing.com//v1/scores \
-H "Authorization: Basic your-api-key-goes-here" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"ip_address":"67.243.228.40",
     "user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)"}'

Errors

The Modern Pricing API uses the following error codes:

Error Code Meaning
400 Bad Request — Your request is invalid.
401 Unauthorized — Your API key is wrong.
404 Not Found — The specified resource could not be found.
429 Too Many Requests — We permit 1,800 requests/min to the API.
500 Internal Server Error — We had a problem with our server. Try again later.
503 Service Unavailable — We're temporarily offline for maintenance. Please try again later.

JavaScript Integration

Use our JavaScript snippet integration to asynchronously request Modern Pricing scores.

Snippet

<script src="https://modernpricing.com/util.js"></script>
<script type="text/javascript">
  window.dataLayer = window.dataLayer || [];
  postData("your-api-key", {
            ip_address: "",
            user_agent: "" })
    .then(response => dataLayer.push({
          score: response.data.attributes.score,
          experiment: { active: response.data.attributes.experiment.active,
          variant: response.data.attributes.experiment.variant }}))
    .catch(error => console.error(error));
  var modernPricing = new DataLayerHelper(dataLayer, listener);
</script>

Then use the JavaScript helper object, modernPricing, to access the Modern Pricing score:

> modernPricing.get('score');
<< ""

Finally, we suggest using the following listener function to update HTML elements on your page:

function listener(model, message) {
  if (message.score) {
    let mp_score_input = document.querySelector("#mp_score_input");

    if (mp_score_input) {
      mp_score_input.value = message.score;
    }
  }
}

And that's it! Please contact us if you have any questions or concerns.