Set item replacements
PUT /v2/fulfillment/users/{user_id}/orders/{order_id}/replacement_selections
For each line item in a delivery or pickup order, you can use this idempotent operation to provide the customer's replacement selections[]
. If the requested line item is out of stock or can't be found, these selections[]
define the customer's preferred replacement.
To successfully perform this operation, the order's status
must be brand_new
, acknowledged
or picking
. After status
advances beyond picking
, the request fails.
You can’t use this operation to add line items to the order. If your request contains line_num
values that don’t exist in the order, then those values are listed in the error's message
.
After an order is created, you can use the update an order operation to add line items.
If you’ve already used a create delivery, create pickup, or update order operation to set a line item’s replacement items, and you specify a replacement_items[]
for that same line item in this request, then the new value overwrites the existing values.
Security
Name | In | Description |
---|---|---|
Authorization | header | The Authorization header with the bearer token acquired during authentication. |
Parameters
Name | In | Type | Required | Description |
---|---|---|---|---|
user_id | path | string | ![]() | The ID of the user. |
order_id | path | string | ![]() | The ID of the order. |
Request
Field | Type | Required | Description |
---|---|---|---|
selections | Array(OrderItemSelection) | ![]() | This array contains the customer's order item replacement selections. These selections are used in the event the requested product is out of stock or can't be found. The array can contain a maximum of ten OrderItemSelection objects. |
OrderItemSelection Object
Field | Type | Required | Description |
---|---|---|---|
line_num | string | ![]() | The order item's line number. |
count | integer | ![]() | The preferred count of the replacement item. Must be greater than '0'. Depending on the item's catalog configuration, either this field or 'weight' is required. |
weight | number | ![]() | The preferred weight of the replacement item. Must be greater than '0'. Depending on the item's catalog configuration, either this field or 'count' is required. The unit of measure, such as lb or kg, assigned to this field is based on the item's catalog configuration. |
replacement_policy | string | ![]() | The policy on how replacements should be handled. One of 'no_replacements', 'users_choice', or 'shoppers_choice' (default). If 'replacement_items' exists, then this field must be 'users_choice'. |
replacement_items | Array(Replacement_items) | ![]() | An array containing the customer’s preferred replacement items. If 'replacement_policy' is 'users_choice', then the number of Replacement_items objects in this array must be '1'. |
item | Item | ![]() | The code of the order line item. |
Replacement_items Object
One of the following:
Field | Type | Required | Description |
---|---|---|---|
upc | string | ![]() | The item's universal product code (upc). |
or
Field | Type | Required | Description |
---|---|---|---|
rrc | string | ![]() | The item's retailer reference code (rrc). |
Item Object
One of the following:
Field | Type | Required | Description |
---|---|---|---|
upc | string | ![]() | The item's universal product code (upc). |
or
Field | Type | Required | Description |
---|---|---|---|
rrc | string | ![]() | The item's retailer reference code (rrc). |
Request examples
- cURL
- Java
- Python
- Go
curl --request PUT \
--url 'https://connect.instacart.com/v2/fulfillment/users/{user_id}/orders/{order_id}/replacement_selections' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"selections": [
{
"line_num": "string",
"count": 1,
"weight": 1,
"replacement_policy": "no_replacements",
"replacement_items": [
{
"upc": "string"
}
],
"item": {
"upc": "string"
}
}
]
}'
HttpResponse<String> response = Unirest.put("https://connect.instacart.com/v2/fulfillment/users/{user_id}/orders/{order_id}/replacement_selections")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("Authorization", "Bearer <token>")
.body("{\n \"selections\": [\n {\n \"line_num\": \"string\",\n \"count\": 1,\n \"weight\": 1,\n \"replacement_policy\": \"no_replacements\",\n \"replacement_items\": [\n {\n \"upc\": \"string\"\n }\n ],\n \"item\": {\n \"upc\": \"string\"\n }\n }\n ]\n}")
.asString();
import http.client
conn = http.client.HTTPSConnection("connect.instacart.com")
payload = "{\n \"selections\": [\n {\n \"line_num\": \"string\",\n \"count\": 1,\n \"weight\": 1,\n \"replacement_policy\": \"no_replacements\",\n \"replacement_items\": [\n {\n \"upc\": \"string\"\n }\n ],\n \"item\": {\n \"upc\": \"string\"\n }\n }\n ]\n}"
headers = {
'Accept': "application/json",
'Content-Type': "application/json",
'Authorization': "Bearer <token>"
}
conn.request("PUT", "/v2/fulfillment/users/{user_id}/orders/{order_id}/replacement_selections", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://connect.instacart.com/v2/fulfillment/users/{user_id}/orders/{order_id}/replacement_selections"
payload := strings.NewReader("{\n \"selections\": [\n {\n \"line_num\": \"string\",\n \"count\": 1,\n \"weight\": 1,\n \"replacement_policy\": \"no_replacements\",\n \"replacement_items\": [\n {\n \"upc\": \"string\"\n }\n ],\n \"item\": {\n \"upc\": \"string\"\n }\n }\n ]\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Response
Field | Type | Required | Description |
---|---|---|---|
id | string | ![]() | The ID of the order. |
warnings | Array(Error) | ![]() | Any warnings associated with this request. |
Error Object
Field | Type | Required | Description |
---|---|---|---|
error | ErrorDetails | ![]() | Information relevant to the error. |
meta | MetaError | ![]() | The error metadata. |
ErrorDetails Object
Field | Type | Required | Description |
---|---|---|---|
message | string | ![]() | The error message. |
error_code | integer | ![]() | The error code. |
MetaError Object
Field | Type | Required | Description |
---|---|---|---|
items | Array(ItemInfo) | ![]() | The items that triggered the error. |
ItemInfo Object
Field | Type | Required | Description |
---|---|---|---|
item_code | string | ![]() | The retailer reference code (RRC) or universal product code (UPC) of an item that triggered the error. |
Response examples
200 Success
200
Replacement selections updated200
Replacement selections updated with no replacements200
Replacement selections updated with warnings
{
"id": "123"
}
{
"id": "123"
}
{
"id": "123",
"warnings": [
{
"error": {
"message": "Some items are not deliverable",
"error_code": 2005
},
"meta": {
"items": [
{
"item_code": "987"
}
]
}
}
]
}
4XX Errors
Error responses return either a single error or multiple errors.
HTTP Code | Cause | Error Message | Error Code | Error Meta |
---|---|---|---|---|
400 | Invalid replacement_policy | "is not included in the list" | 1001 | {"key":"selections[0].replacement_policy"} |
400 | Missing required fields | "can't be blank" | 1001 | {"key":"selections[0].item"} |
400 | Invalid count | "must be greater than or equal to 0" | 1001 | {"key":"selections[0].count"} |
400 | Invalid weight | "must be greater than or equal to 0" | 1001 | {"key":"selections[0].weight"} |
400 | Too many selections | "Maximum 10 items allowed" | 1001 | {"key":"selections"} |
400 | Duplicate line numbers | "Duplicate line_num values not allowed" | 2006 | {"duplicate_line_nums":["1"]} |
400 | Both count and weight present | "Exactly one of count or weight must be present for line_nums: 1" | 4001 | Not applicable |
400 | Neither count nor weight present | "Exactly one of count or weight must be present for line_nums: 1" | 4001 | Not applicable |
400 | Invalid replacement policy with replacement items | "Replacement policy must be users_choice when replacement_items are present for line_nums: 1" | 4001 | Not applicable |
400 | Invalid replacement policy with users_choice replacement policy | "Replacement items must contain one item when replacement policy is users_choice for line_nums: 1" | 4001 | Not applicable |
404 | Order not found | "Order not found" | 4000 | Not applicable |
404 | Missing line numbers | "Order line item not found for line_nums: 2" | 4000 | Not applicable |