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.

Adding Links to Your Resource

Adding Links to Your Resource

The goal of this tutorial is to add a new link between resources. You will enhance the terms and conditions resource you created in Writing Your First Resource by linking it from the orders resource. After completing this tutorial, you will be able to view the terms and conditions resource by following a link on the orders resource.

Linking from Orders to Terms and Conditions

We will add a link from an order to the terms and conditions so that a client application can retrieve the terms and conditions for an order by following or zooming into the link. The order representation after including the link should look as follows:
{
  "self": {
    "type": "elasticpath.orders.order",
    "uri": "/commerce-legacy/orders/{scope}/{order-id}",
    "href": "http://localhost/cortex/orders/mobee/<an-order-id>",
    "max-age": 0
  },
  "links": [
    ...
    {  
        "rel":"terms",
        "type":"elasticpath.terms.terms-and-conditions",
        "uri":"/commerce-legacy/terms/id=",
        "href":"http://localhost:9080/cortex/termswithlink/id="
    },
    ...
  ]
}
A client application can follow the link with rel terms to retrieve the terms and conditions for an order.