Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support V2 endpoints #33

Merged
merged 7 commits into from
Jan 6, 2025
Merged

feat: support V2 endpoints #33

merged 7 commits into from
Jan 6, 2025

Conversation

spencerlepine
Copy link
Owner

@spencerlepine spencerlepine commented Jan 5, 2025

Checklist

@spencerlepine spencerlepine self-assigned this Jan 5, 2025
@spencerlepine spencerlepine added the in-progress acknowledged, fix in development label Jan 5, 2025
@spencerlepine
Copy link
Owner Author

Improved Logging

Before

import Printify, { Webhook } from 'printify-sdk-js';

const printify = new Printify({
  shopId: '12345',
   accessToken: '{{API_KEY}},
  enableLogging: true,
});

(async () => {
  const webhooks: Webhook[] = await printify.webhooks.list();
  console.log(webhooks[0]); // { "topic": "order:created", "url": "https://example.com/webhooks/order/created", "shop_id": "1", "id": "5cb87a8cd490a2ccb256cec4" }
})();
# request log
$ tsc && node app.js
Requesting GET https://api.printify.com/v1/shops/12345/webhooks.json
# request error
$ tsc && node app.js
Printify SDK Error: 401 Unauthorized - Requested URL: https://api.printify.com/v1/shops/123456/webhooks.json
/workspaces/printify-sdk-js/examples/typescript/node_modules/printify-sdk-js/dist/index.cjs.js:1
//...
{super(t),this.list=nt.bind(this),this.create=it.bind(this),this.updateOne=ot.bind(this),this.deleteOne=rt.bind(this)}}module.exports=class{constructor(t){if(!t.accessToken)throw new Error("accessToken is required");this.shopId=t.shopId,this.catalog=new S(t),this.v2={catalog:new N(t)},this.orders=new G(t),this.products=new K(t),this.shops=new Z(t),this.uploads=new et(t),this.webhooks=new ht(t)}};
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

Error: Printify SDK Error: 401 Unauthorized - Requested URL: https://api.printify.com/v1/shops/123456/webhooks.json
    at ht.request (/workspaces/printify-sdk-js/examples/typescript/node_modules/printify-sdk-js/dist/index.cjs.js:1:5029)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.18.1
error Command failed with exit code 1.

After

import Printify, { Webhook } from 'printify-sdk-js';

const printify = new Printify({
  shopId: '12345',
   accessToken: '{{API_KEY}},
  enableLogging: true,
});

(async () => {
  const webhooks: Webhook[] = await printify.webhooks.list();
  console.log(webhooks[0]); // { "topic": "order:created", "url": "https://example.com/webhooks/order/created", "shop_id": "1", "id": "5cb87a8cd490a2ccb256cec4" }
})();
# request log
$ tsc && node app.js
[2025-01-06T11:51:56.573Z] Request: GET https://api.printify.com/v1/shops/12345/webhooks.json
# request error
$ tsc && node app.js
$ tsc && node app.js
[2025-01-06T12:35:13.540Z] Request: GET https://api.printify.com/v1/shops/123456/webhooks.json
Printify SDK Error: 401 Unauthorized - Requested URL: https://api.printify.com/v1/shops/123456/webhooks.json
[Error: Printify SDK Error: 401 Unauthorized - Requested URL: https://api.printify.com/v1/shops/123456/webhooks.json]
Done in 2.54s.

@spencerlepine spencerlepine merged commit a9f8b6d into main Jan 6, 2025
5 checks passed
@spencerlepine spencerlepine deleted the dev1.3.0 branch January 6, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-progress acknowledged, fix in development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant