Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I have been struggling with this for days now. I am trying to pass a variable to the action function to update app metafields on a submit button click. No matter which way I try, I am always getting back an error relating to the passed variable being null. This is the code I have:
The button click:
const handleSubmit = async () => {
const dateValue = textFieldValue;
console.log('after key presses: '+dateValue);
submit( {variables: { myKey: dateValue }} , { replace: true, method: "post" });
}
and here is the code for the submit action:
export const action = async ({ request, myKey }) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CreateAppDataMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafieldsSetInput) {
metafields {
id
namespace
value
key
}
userErrors {
field
message
}
}
}`,
{
variables: {
"metafieldsSetInput": [
{
"namespace": "settings-attributes",
"key": "date-available",
"type": "boolean",
"value": "false",
"ownerId": globalAppId
},
{
"namespace": "settings-attributes",
"key": "date",
"type": "single_line_text_field",
"value": myKey,
"ownerId": globalAppId
}
]
},
},
);
const data = await response.json();
return json({
data,
});
};
If anyone has any ideas, I would be VERY grateful. Thanks
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025