├── package.json
├── .gitignore
├── index.js
└── front.js
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "update-order-note-api",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node index.js"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "axios": "^1.6.0",
13 | "body-parser": "^1.20.2",
14 | "cors": "^2.8.5",
15 | "express": "^4.18.2"
16 | },
17 | "engines": {
18 | "node": "^16.20.2"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 |
16 |
17 | # production
18 | /build
19 |
20 | # misc
21 | .DS_Store
22 | *.pem
23 |
24 | # debug
25 | npm-debug.log*
26 | yarn-debug.log*
27 | yarn-error.log*
28 | .pnpm-debug.log*
29 |
30 | # local env files
31 | .env*.local
32 |
33 | # vercel
34 | .vercel
35 |
36 | # typescript
37 | *.tsbuildinfo
38 | next-env.d.ts
39 | /.github/
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const app = express();
3 | const port = 3000;
4 | const bodyParser = require("body-parser");
5 | const cors = require("cors");
6 | const axios = require("axios");
7 |
8 | app.use(bodyParser.json());
9 | app.use(cors());
10 |
11 | app.post("/update_order", (req, res) => {
12 | const { orderId, note, attributes } = req.body;
13 | const noteAttributes = [];
14 | Object.keys(attributes).forEach((attr) => {
15 | noteAttributes.push({
16 | name: attr,
17 | value: attributes[attr],
18 | });
19 | });
20 |
21 | axios
22 | .put(
23 | `https://8cf85f.myshopify.com/admin/api/2023-10/orders/${orderId}.json`,
24 | JSON.stringify({
25 | order: { id: orderId, note: note, note_attributes: noteAttributes },
26 | }),
27 | {
28 | headers: {
29 | "Content-Type": "application/json",
30 | "X-Shopify-Access-Token": "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",
31 | },
32 | }
33 | )
34 | .then(function (response) {
35 | res.send("updated!");
36 | })
37 | .catch(function (err) {
38 | res.send(err);
39 | });
40 | });
41 |
42 | app.post("/update", (req, res) => {
43 | const { payload } = req.body;
44 |
45 | const mesurementID = "G-TSLJKQSFB3";
46 | const apiSecretKey = "rRCZXTRsTQKFx-fvygSD3w";
47 |
48 | axios
49 | .post(
50 | `https://www.google-analytics.com/mp/collect?measurement_id=${mesurementID}&api_secret=${apiSecretKey}`,
51 | JSON.stringify(payload),
52 | {
53 | headers: {
54 | "Content-Type": "application/json",
55 | },
56 | }
57 | )
58 | .then(function (response) {
59 | console.log(response);
60 | res.send("updated!");
61 | })
62 | .catch(function (err) {
63 | res.send("error");
64 | });
65 | // fetch(
66 | // `https://www.google-analytics.com/mp/collect?measurement_id=${mesurementID}&api_secret=${apiSecretKey}`,
67 | // {
68 | // method: "POST",
69 | // body: JSON.stringify(payload),
70 | // }
71 | // )
72 | // .then(function (response) {
73 | // console.log(response);
74 | // res.send("success");
75 | // })
76 | // .catch(function (err) {
77 | // res.send("fail");
78 | // });
79 | });
80 |
81 | app.listen(port, () => {
82 | console.log(`Example app listening on port ${port}`);
83 | });
84 |
--------------------------------------------------------------------------------
/front.js:
--------------------------------------------------------------------------------
1 |
2 |
6 |
15 |
16 |
206 |
207 | {%- if customer -%}
208 |
225 | {%- else -%}
226 |
243 | {%- endif -%}
244 |
245 |
246 |
247 |
314 |
--------------------------------------------------------------------------------