I am creating an app, and I want to put JavaScript in the theme with graphQL and rest api.

YUNJAE
New Member
2 0 0

JavaScript and liquid I want to put

{% if product %}
                <script type="text/javascript" async>
                    if(!window.vudoir) window.products = {};
                    window.products[{{ product.id }}] = {{product | json}};
                    console.log(window.products[{{ product.id }}]);
                </script>
{% endif %}

 

Trying rest api and graphQL

rest api

const javascriptPutResponse = await fetch(`https://${shop}/admin/api/2020-04/themes/${themeId}/assets.json`, JSON.stringify(PUT_THEME_SCRIPT) ,{
    method: 'PUT'
})
.then(res => console.log(res))

graphQL

rest api and graphQL are both the same result, so omit

 

result console

Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:78:25)
at writeGeneric (internal/stream_base_commons.js:73:3)
at Socket._writeGeneric (net.js:714:5)
at Socket._write (net.js:726:8)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
at Socket.Writable.write (_stream_writable.js:299:11)
at ServerResponse._writeRaw (_http_outgoing.js:272:17)
at ServerResponse._send (_http_outgoing.js:236:15)
at ServerResponse.end (_http_outgoing.js:714:10)
at IncomingMessage.<anonymous> (/ { My path }/node_modules/next/dist/compiled/webpack-hot-middleware/middleware.js:1:1931)
at IncomingMessage.emit (events.js:203:15)
at abortIncoming (_http_server.js:463:9)
at socketOnEnd (_http_server.js:478:5)
at Socket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)

event - compiled successfully
[Network error]: Error: only absolute urls are supported
Body {
url:
'https://xxxxxxxxxx.myshopify.com/admin/api/2020-04/themes/102327****/assets.json',     //Replaced with * for token security
status: 401,
statusText: 'Unauthorized',

...

 

HELP ME!

 

0 Likes