Reading Predictions

Once a JWT has been retrieved using the /authorize endpoint, you can retrieve predictions for your active ML models. If an invalid JWT is used, the predictions endpoint will return an error.

Get Predictions Endpoint

GET https://service.morphlapis.com/predictions/<account>/<models>/get

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "<model>": <prediction>
}
{
    status: 0, 
    error: "Error message"
}

In the above table:

  • <account> represents your unique account number, which can be retrieved from the MorphL Dashboard > API section.
  • <models> is a list of models identifiers, separated by /. For example, if <models> = shopping_stage, the endpoint will return the prediction value for the Shopping Stage Completess model. If <models> = shopping_stage/cart_abandonment, the endpoint will return the predictions values for both the Shopping Stage Completess and Cart Abandonment models. Please visit the complete list of unique identifiers for each model.

    If multiple models are passed in the <models> route parameter, the response will contain a <model>:<prediction> pair for each.
  • <token> is the JWT returned by the /authorize endpoint.
  • <prediction> represents the prediction value, either a float number or a JSON object for multiclass classification ML models.

You can see below examples of retrieving predictions for each model type.

Retrieve predictions for Shopping Stage Completeness ML model

GET https://service.morphlapis.com/predictions/<account>/shopping_stage/get

Parameters:

Name Required Description
client_id Yes Unique ID for your users. For models that use Google Analytics or Google Analytics 360 data, this parameter represents the Google Analytics Client ID.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "shopping_stage": <float>
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Cart Abandonment ML model

GET https://service.morphlapis.com/predictions/<account>/cart_abandonment/get

Parameters:

Name Required Description
client_id Yes Unique ID for your users. For models that use Google Analytics or Google Analytics 360 data, this parameter represents the Google Analytics Client ID.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "cart_abandonment": <float>
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Customers LTV ML model

GET https://service.morphlapis.com/predictions/<account>/customers_ltv/get

Parameters:

Name Required Description
client_id Yes Unique ID for your users. For models that use Google Analytics or Google Analytics 360 data, this parameter represents the Google Analytics Client ID.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "customers_ltv":
    {
        "lower_tier": <float>,
        "medium_tier": <float>,
        "upper_tier": <float>
    }
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for User Search Intent ML model

GET https://service.morphlapis.com/predictions/<account>/user_search_intent/get

Parameters:

Name Required Description
client_id Yes Search query (keywords)

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "user_search_intent":
    {
        "informational": <float>,
        "consideration": <float>,
        "navigational": <float>,
        "transactional": <float>
    }
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Personalized Recommendations ML model

GET https://service.morphlapis.com/predictions/<account>/personalized_recommendations/get

Parameters:

Name Required Description
client_id Yes Unique ID for your users. For models that use Google Analytics or Google Analytics 360 data, this parameter represents the Google Analytics Client ID.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "personalized_recommendations":
    {
        "item_sku1": <float>,
        "item_sku2": <float>,
        "item_sku3": <float>,
        [...]
    }
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Related Products ML model

GET https://service.morphlapis.com/predictions/<account>/related_products/get

Parameters:

Name Required Description
item_sku Yes ID (SKU) for your product.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "related_products":
    {
        "item_sku1": <float>,
        "item_sku2": <float>,
        "item_sku3": <float>,
        [...]
    }
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Frequently Bought Together ML model

GET https://service.morphlapis.com/predictions/<account>/bought_together/get

Parameters:

Name Required Description
item_sku Yes ID (SKU) for your product.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "bought_together":
    {
        "item_sku1": <float>,
        "item_sku2": <float>,
        "item_sku3": <float>,
        [...]
    }
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Churning Users ML model

GET https://service.morphlapis.com/predictions/<account>/churning_users/get

Parameters:

Name Required Description
client_id Yes Unique ID for your users. For models that use Google Analytics or Google Analytics 360 data, this parameter represents the Google Analytics Client ID.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "churning_users": <float>
}
{
    status: 0, 
    error: "Error message"
}

Retrieve predictions for Next Order Value ML model

GET https://service.morphlapis.com/predictions/<account>/next_order_value/get

Parameters:

Name Required Description
client_id Yes Unique ID for your users. For models that use Google Analytics or Google Analytics 360 data, this parameter represents the Google Analytics Client ID.

Request / response format:

Request Headers Success Response Error Response
Authorization:
<token>
{
    "status": 1,
    "next_order_value": <float>
}
{
    status: 0, 
    error: "Error message"
}

Quick start example

Make request using curl:

$ JWT_TOKEN=eyJ0eXAiOi3erdf4iOiJIUzI1NiJ9.eyJpc3MiOiJtb3...
$ ACCOUNT=92726
$ IDENTIFIER=GA319361.317391

$ curl \
  -X GET \
  -H "Authorization: $JWT_TOKEN" \
  https://service.morphlapis.com/predictions/${ACCOUNT}/shopping_stage/get?client_id=${IDENTIFIER}

Example response:

{
    "status":1,
    "shopping_stage":0.8707
}

Reading predictions from multiple models with a single request

For optimizing requests, the MorphL API allows you to read predictions from multiple models with a single request. Only predictions from models with the same required parameters (client_id and/or item_sku) can be retrieved with a single request (ex. related_products and bought_together).

Below you can see a sample request for reading Shopping Stage Completeness and Cart Abandonment predictions for the same client_id.

Make request using curl:

$ JWT_TOKEN=eyJ0eXAiOi3erdf4iOiJIUzI1NiJ9.eyJpc3MiOiJtb3...
$ ACCOUNT=92726
$ IDENTIFIER=GA319361.317391

$ curl \
  -X GET \
  -H "Authorization: $JWT_TOKEN" \
  https://service.morphlapis.com/predictions/${ACCOUNT}/shopping_stage/cart_abandonment/get?client_id=${IDENTIFIER}

Example response:

{
    "status":1,
    "shopping_stage":0.8707,
    "cart_abandonment":0.2301
}