Solved

Input variables for function. Error: input.variables: Variable definitions are missing.

fabiof4011
Shopify Partner
5 2 0

I'm trying to use a variable in my input query for a shipping customisation function.

 

I've followed the steps here https://shopify.dev/docs/apps/functions/input-output/variables-queries

 

But I'm getting the following error

Validation errors 
 • input.variables: Variable definitions are missing. Ensure you have defined them in your extension
 configuration and that you are using a supported CLI version. See documentation for details:
  https://shopify.dev/api/functions/input-query-variables 

 

My shopify cli is at the latest available version (3.50.1)

 

My extensions/my-delivery-customisation/shopify.extension.toml file looks like this

 

 

api_version = "2023-10"
[[extensions]]
handle = "my-delivery-customization"
name = "t:name"
description = "t:description"
type = "function"

[[extensions.targeting]]
target = "purchase.delivery-customization.run"
input_query = "src/run.graphql"
export = "run"

[extensions.build]
command = ""
path = "dist/function.wasm"

[extensions.ui.paths]
create = "/"
details = "/"

[input.variables]
namespace = "$app:my-delivery-function"
key = "shipping-config"

 

 

My query looks like this

 

 

query RunInput($freeTags: [String!]) {
    cart{
        buyerIdentity {
            email
            customer{
                isVIP: hasAnyTag(tags: $freeTags)
            }
        }
        deliveryGroups {
            deliveryOptions {
                title
                handle
            }
        }
    }
}

 

 

I have created a json metafield with that key and that namespace.

 

Thank you for your help

 

Accepted Solution (1)

fabiof4011
Shopify Partner
5 2 0

This is an accepted solution.

Ok the problem was that (differently from what the documentation says) the right syntax is this:

 

[extensions.input.variables]
namespace = "$app:my-delivery-function"
key = "shipping-config"

View solution in original post

Replies 8 (8)

fabiof4011
Shopify Partner
5 2 0

This is an accepted solution.

Ok the problem was that (differently from what the documentation says) the right syntax is this:

 

[extensions.input.variables]
namespace = "$app:my-delivery-function"
key = "shipping-config"
Nick_Wesselman
Shopify Staff
123 31 49

Thanks for posting the solution -- we indeed have a doc update in the works for this.

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

rishika_286
Shopify Partner
11 0 0

I am also doing the same thing but after writing this 
[extensions.input.variables]
namespace = "payment-customization"
key = "function-configuration"

metafield giving Null, I am stucked to solve this issue.

fabiof4011
Shopify Partner
5 2 0

Are you using the $app prefix? Try to not use that and see if it works.

rishika_286
Shopify Partner
11 0 0

No, I am not using $app (reserved prefix) for this.Screenshot from 2023-11-02 14-30-15.pngScreenshot from 2023-11-02 14-30-07.png

Nick_Wesselman
Shopify Staff
123 31 49

When you say 'metafield giving null', are you getting the "Variable Definitions Are Missing" error, or is the metafield coming back null in your input query?

 

These are two different but related uses of metafields in Functions.

 

https://shopify.dev/docs/apps/functions/input-output/queries-metafields

https://shopify.dev/docs/apps/functions/input-output/variables-queries

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

rishika_286
Shopify Partner
11 0 0

Yes, in input query it's giving null. Getting this response

Screenshot from 2023-11-02 18-11-33.png

Nick_Wesselman
Shopify Staff
123 31 49

I responded in your other thread.

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog