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

NeedInfo

NeedInfo

Needinfos are a hypermedia control that prevent a resource from changing its state until a set of conditions are satisfied. Needinfos are generally used to control a button's enabled state on the user interface.

NeedInfo Example: Completing a Purchase

The purchase form resource creates a purchase. The submitorderaction link appears on the purchase form when the purchases preconditions are satisfied and a purchase can be placed. Below is a purchase form with its preconditions satisfied.
{
  "self": {
    "type": "elasticpath.purchases.purchase",
    "uri": "/purchases/orders/mobee/mu3=/form",
    "href": "http://api.elasticpath.net/cortex/purchases/orders/mobee/mu3=/form",
    "max-age": 0
  }  
  "links": [
    {
      "rel": "submitorderaction",
      "uri": "/purchases/orders/mobee/mu3=",
      "href": "http://api.elasticpath.net/cortex/purchases/orders/mobee/mu3="
    }
  ]
}    
If a purchases preconditions are not satisfied and more information is required from the shopper, needinfo links appear instead of the submitorderaction link for each piece of missing information. needinfos points to an info resource that allows the shopper to select or create the missing data. The example below shows needinfos appearing on a purchase form.
{
  "self": {
    "type": "elasticpath.purchases.purchase",
    "uri": "/purchases/orders/mobee/mu3=/form",
    "href": "http://api.elasticpath.net/cortex/purchases/orders/mobee/mu3=/form",
    "max-age": 0
  }  
  "links": [
    {
      "rel": "needinfo",
      "type": "elasticpath.controls.info",
      "uri": "/orders/mobee/grr=/billingaddressinfo",
      "href": "http://api.elasticpath.net/cortex/orders/mobee/grr=/billingaddressinfo"
    },    
    {
      "rel": "needinfo",
      "type": "elasticpath.controls.info",
      "uri": "/orders/mobee/grr=/emailinfo",
      "href": "http://api.elasticpath.net/cortex/orders/mobee/grr=/emailinfo"
    }
  ]
}