I’m in the process of migrating my TS/JS product discount function over to use Rust and the new discount function API (version 2025-10).
In testing the migration by switching out the old function uid to the new rust function, the automatic product discounts work great but when I try to use a discount code it bugs out with InvalidOutputError errors and I’m not sure how to go about fixing it.
When running automatic product discounts it works great and the output looks like this:
output": {
"operations": [
{
"productDiscountdddsAdd": {
"candidates": [
{
"associatedDiscountCode": null,
"message": "DISCOUNT",
"targets": [
{
"cartLine": {
"id": "gid://shopify/CartLine/0",
"quantity": null
}
}
],
"value": {
"percentage": {
"value": "22.0"
}
}
}
],
"selectionStrategy": "ALL"
}
}
]
},
"outputBytes": 199,
"logs": [],
"functionId": "8ab17e69-41c7-48e6-a5e5-a92c8eb482f7",
"fuelConsumed": 99210,
"target": "cart.lines.discounts.generate.run",
But then I try with a discount code and it errors:
"output": {
"operations": [
{
"productDiscountsAdd": {
"candidates": [
{
"associatedDiscountCode": {
"code": "HAY"
},
"message": "DISCOUNT",
"targets": [
{
"cartLine": {
"id": "gid://shopify/CartLine/0",
"quantity": null
}
}
],
"value": {
"percentage": {
"value": "55.0"
}
}
}
],
"selectionStrategy": "ALL"
}
}
]
},
"outputBytes": 208,
"logs": [],
"functionId": "8ab17e69-41c7-48e6-a5e5-a92c8eb482f7",
"fuelConsumed": 87894,
"target": "cart.lines.discounts.generate.run",
"errorMessage": [
{
"path": [],
"explanation": "Associated discount codes must be included in the enteredDiscountCodesAccept operation."
}
],
"errorType": "InvalidOutputError",
Ok so I just need to include enteredDiscountCodesAccept then:
output": {
"operations": [
{
"productDiscountsAdd": {
"candidates": [
{
"associatedDiscountCode": {
"code": "HAY"
},
"message": "DISCOUNT",
"targets": [
{
"cartLine": {
"id": "gid://shopify/CartLine/0",
"quantity": null
}
}
],
"value": {
"percentage": {
"value": "55.0"
}
}
}
],
"selectionStrategy": "ALL"
}
},
{
"enteredDiscountCodesAccept": {
"codes": [
{
"code": "HAY"
}
]
}
}
]
},
"outputBytes": 254,
"logs": [],
"functionId": "8ab17e69-41c7-48e6-a5e5-a92c8eb482f7",
"fuelConsumed": 91108,
"target": "cart.lines.discounts.generate.run",
"errorMessage": [
{
"path": [],
"explanation": "The enteredDiscountCodesAccept operation requires the shop to have network access enabled"
}
],
And now it says the shop needs to have network access enabled despite none of the features requiring network access. But I enable it anyway in my toml:
api_version = "2025-10"
[[extensions]]
name = "t:name"
handle = "discount-product-2"
type = "function"
uid = "3859b1e6-e487-5009-641c-f31a59a7f898067f7f11"
description = "t:description"
[[extensions.targeting]]
target = "cart.lines.discounts.generate.run"
input_query = "src/cart_lines_discounts_generate_run.graphql"
export = "cart_lines_discounts_generate_run"
[extensions.build]
command = "cargo build --target=wasm32-wasip1 --release"
path = "target/wasm32-wasip1/release/discount-product-2.wasm"
watch = [ "src/**/*.rs" ]
[extensions.capabilities]
network_access = true
[extensions.input.variables]
namespace = "..."
key = "input_variables"
But it still gives the same error.
I checked the app settings and it had network access enabled too. I’m not sure what I’m doing wrong or what I’m supposed to do but does anyone know what I’m missing to get discount codes working, or if there’s a way to do this without network access because I’m not looking to making any external calls, or if there’s another way to do this without specifying associated_discount_code?