Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

FollowLocation

FollowLocation

The FollowLocation query parameter reduces the number of requests required when performing POST operations. FollowLocation instructs Cortex to retrieve the resource referenced in the Location header and return it in the response body which eliminates the need to make another call to retrieve the resource. FollowLocation can also be used with zoom to further reduce the number of HTTP requests required.

Example: Add item to cart using FollowLocation

Appending the FollowLocation query parameter instructs Cortexto return the resource referenced in the location header. For example, the item resource's addtocartform enables you to add the item to a cart. To add the item to the cart and automatically retrieve the response, construct a POST request using the form fields as the request body and the URL defined by the action link then append the FollowLocation query parameter to the request:

POST /carts/mobee/default/lineitems/items/mobee/m5yxi=?FollowLocation
{
  "quantity" : 1
}
{
  "self": {
    "type": "elasticpath.collections.links",
    "uri": "/commerce-legacy/carts/mobee/guz=/lineitems",
    "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems",
    "max-age": 0
  },
  "links": [
    {
      "rel": "element",
      "rev": "list",
      "type": "elasticpath.carts.line-item",
      "uri": "/commerce-legacy/carts/mobee/guz=/lineitems/hfq=",
      "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems/hfq="
    },
    {
      "rel": "element",
      "rev": "list",
      "type": "elasticpath.carts.line-item",
      "uri": "/commerce-legacy/carts/mobee/guz=/lineitems/gbq=",
      "href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems/gbq="
    },
    {
      "rel": "cart",
      "rev": "lineitems",
      "type": "elasticpath.carts.cart",
      "uri": "/commerce-legacy/carts/mobee/guz=",
      "href": "http://api.elasticpath.net/cortex/carts/mobee/guz="
    }
  ]
}

Example: Keyword Search using FollowLocation and Zoom

FollowLocation can be combined with Zoom to retrieve the resource referenced in the location header and well as any of that resource's links. For example, the search resource's keywordsearchform enables you to perform a keyword search for an item. To search for an the item and automatically retrieve the each search result's links, construct a POST request using the form fields as the request body and the URL defined by the action link then append the FollowLocation and Zoom query parameters to the request. The response includes the resource's links as per normal zoom rules.

POST /searches/mobee/keywords/items?FollowLocation&Zoom=element:definition
{
   "keywords" : "test"
}
201 CREATED
{
  "self": {
    "type": "elasticpath.collections.paginated-links",
    "uri": "/commerce-legacy/searches/mobee/keywords/items/m43g==?zoom=element:definition",
    "href": "http://api.elasticpath.com/cortex/searches/mobee/keywords/items/m43g==?zoom=element:definition",
    "max-age": 600
  },
  "pagination": {
    "current": 1,
    "page-size": 5,
    "pages": 1,
    "results": 3,
    "results-on-page": 3
  },
  "links": [
    {
      "rel": "element",
      "type": "elasticpath.items.item",
      "uri": "/commerce-legacy/items/mobee/m5y2=",
      "href": "http://api.elasticpath.com/cortex/items/mobee/m5y2="
    },
    {
      "rel": "element",
      "type": "elasticpath.items.item",
      "uri": "/commerce-legacy/items/mobee/m5yq=",
      "href": "http://api.elasticpath.com/cortex/items/mobee/m5yq="
    },
    {
      "rel": "element",
      "type": "elasticpath.items.item",
      "uri": "/commerce-legacy/items/mobee/m5ya=",
      "href": "http://api.elasticpath.com/cortex/items/mobee/m5ya="
    }
  ],
  "_element": [
    {
      "_definition": [
        {
          "self": {
            "type": "elasticpath.itemdefinitions.item-definition",
            "uri": "/commerce-legacy/itemdefinitions/mobee/m5y2=",
            "href": "http://api.elasticpath.com/cortex/itemdefinitions/mobee/m5y2=",
            "max-age": 600
          },
          "links": [
            {
              "rel": "item",
              "rev": "definition",
              "type": "elasticpath.items.item",
              "uri": "/commerce-legacy/items/mobee/m5y2=",
              "href": "http://api.elasticpath.com/cortex/items/mobee/m5y2="
            },
            {
              "rel": "assets",
              "rev": "definition",
              "type": "elasticpath.collections.links",
              "uri": "/commerce-legacy/assets/itemdefinitions/mobee/m5y2=",
              "href": "http://api.elasticpath.com/cortex/assets/itemdefinitions/mobee/m5y2="
            }
          ],
          "display-name": "Gravity"
        }
      ]
    },
    {
      "_definition": [
        {
          "self": {
            "type": "elasticpath.itemdefinitions.item-definition",
            "uri": "/commerce-legacy/itemdefinitions/mobee/m5yq=",
            "href": "http://api.elasticpath.com/cortex/itemdefinitions/mobee/m5yq=",
            "max-age": 600
          },
          "links": [
            {
              "rel": "item",
              "rev": "definition",
              "type": "elasticpath.items.item",
              "uri": "/commerce-legacy/items/mobee/m5yq=",
              "href": "http://api.elasticpath.com/cortex/items/mobee/m5yq="
            },
            {
              "rel": "assets",
              "rev": "definition",
              "type": "elasticpath.collections.links",
              "uri": "/commerce-legacy/assets/itemdefinitions/mobee/m5yq=",
              "href": "http://api.elasticpath.com/cortex/assets/itemdefinitions/mobee/m5yq="
            }
          ],
          "display-name": "Transformers Female"
        }
      ]
    },
    {
      "_definition": [
        {
          "self": {
            "type": "elasticpath.itemdefinitions.item-definition",
            "uri": "/commerce-legacy/itemdefinitions/mobee/m5ya=",
            "href": "http://api.elasticpath.com/cortex/itemdefinitions/mobee/m5ya=",
            "max-age": 600
          },
          "links": [
            {
              "rel": "item",
              "rev": "definition",
              "type": "elasticpath.items.item",
              "uri": "/commerce-legacy/items/mobee/m5ya=",
              "href": "http://api.elasticpath.com/cortex/items/mobee/m5ya="
            },
            {
              "rel": "assets",
              "rev": "definition",
              "type": "elasticpath.collections.links",
              "uri": "/commerce-legacy/assets/itemdefinitions/mobee/m5ya=",
              "href": "http://api.elasticpath.com/cortex/assets/itemdefinitions/mobee/m5ya="
            }
          ],
          "display-name": "Transformers Over 50"
        }
      ]
    }
  ]
}