Hello I have been following the tutorial here https://shopify.dev/docs/apps/selling-strategies/discounts/experience/ui
Everything has been working up until the frontend part, I have been checking the code back and forth but can not see what I have done different to the example code. If anyone can help with the following errors I would be very grateful!
When I click Save in the discount form I get the following errors in the terminal.
…/web/index.js:82
web-backend │ session: res.locals.shopify.session
web-backend │ ^
web-backend │ TypeError: Cannot read properties of undefined (reading ‘session’)
at runDiscountMutation (…/web/index.js:82:33)
web-backend │…/web/index.js:58:9
And these errors in the console.
XHR POST https://…/api/discounts/automatic
[HTTP/2 500 Internal Server Error 101ms]
Uncaught (in promise) SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Here is the json request from the POST
{
“discount”: {
“functionId”: “*******************************”,
“combinesWith”: {
“orderDiscounts”: false,
“productDiscounts”: false,
“shippingDiscounts”: false
},
“startsAt”: “2023-07-07T09:32:21.415Z”,
“endsAt”: null,
“metafields”: [{
“namespace”: “$app:order-discount”,
“key”: “function-configuration”,
“type”: “json”,
“value”: “{"percentage":20,"amount":20,"maximum":100}”
}],
“title”: “testing”
}
}