Skip to content

Commit f2c34a2

Browse files
committed
[Components] printful #15140
Sources - New Order (Instant) - New Product Added (Instant) - New Order Status Updated (Instant) Actions - Create Order - Calculate Shipping Rates - Update Product
1 parent 9edde6e commit f2c34a2

File tree

14 files changed

+889
-664
lines changed

14 files changed

+889
-664
lines changed

components/printful/actions/calculate-shipping-rates/calculate-shipping-rates.mjs

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,88 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import printful from "../../printful.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "printful-calculate-shipping-rates",
66
name: "Calculate Shipping Rates",
7-
description: "Fetches available shipping rates for a given destination. [See the documentation](https://developers.printful.com/docs/)",
8-
version: "0.0.{{ts}}",
7+
description: "Fetches available shipping rates for a given destination. [See the documentation](https://developers.printful.com/docs/#tag/Shipping-Rate-API/operation/calculateShippingRates)",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
printful,
12-
shippingRecipientAddress: {
12+
storeId: {
1313
propDefinition: [
1414
printful,
15-
"shippingRecipientAddress",
15+
"storeId",
1616
],
1717
},
18-
shippingProductDetails: {
19-
propDefinition: [
20-
printful,
21-
"shippingProductDetails",
22-
],
18+
address1: {
19+
label: "Address 1",
20+
description: "The address 1",
21+
type: "string",
22+
},
23+
city: {
24+
label: "City",
25+
description: "The city",
26+
type: "string",
27+
},
28+
stateCode: {
29+
label: "State Code",
30+
description: "The state code. E.g. `SC`",
31+
type: "string",
32+
},
33+
countryCode: {
34+
label: "Country Code",
35+
description: "The country code. E.g. `BR`",
36+
type: "string",
37+
},
38+
zip: {
39+
label: "ZIP/Postal Code",
40+
description: "The ZIP/postal code. E.g. `89221525`",
41+
type: "string",
42+
},
43+
phone: {
44+
label: "Phone",
45+
description: "The phone number",
46+
type: "string",
47+
optional: true,
48+
},
49+
items: {
50+
type: "string[]",
51+
label: "Items",
52+
description: "A list of items in JSON format. **Example: [{\"variant_id\": \"123456\", \"external_variant_id\": \"123456\", \"quantity\": 123, \"value\": \"12345\" }]**",
53+
},
54+
currency: {
55+
type: "string",
56+
label: "Currency",
57+
description: "3 letter currency code (optional), required if the rates need to be converted to another currency instead of store default currency",
58+
optional: true,
59+
},
60+
locale: {
61+
type: "string",
62+
label: "Locale",
63+
description: "Locale in which shipping rate names will be returned. Available options: `en_US` (default), `es_ES`",
64+
optional: true,
2365
},
2466
},
2567
async run({ $ }) {
2668
const shippingRates = await this.printful.fetchShippingRates({
27-
shippingRecipientAddress: this.shippingRecipientAddress,
28-
shippingProductDetails: this.shippingProductDetails,
69+
$,
70+
headers: {
71+
"X-PF-Store-Id": this.storeId,
72+
},
73+
data: {
74+
recipient: {
75+
address1: this.address1,
76+
city: this.city,
77+
state_code: this.stateCode,
78+
country_code: this.countryCode,
79+
zip: this.zip,
80+
phone: this.phone,
81+
},
82+
items: parseObject(this.items),
83+
currency: this.currency,
84+
locale: this.locale,
85+
},
2986
});
3087
$.export("$summary", "Fetched shipping rates successfully");
3188
return shippingRates;
Lines changed: 114 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,144 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import printful from "../../printful.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
5-
key: "printful-create-order",
65
name: "Create Order",
7-
description: "Creates a new order in your Printful account. [See the documentation]()",
8-
version: "0.0.{{ts}}",
6+
version: "0.0.1",
7+
key: "printful-create-order",
8+
description: "Creates a new order in your Printful account. [See docs here](https://developers.printful.com/docs/#operation/createOrder)",
99
type: "action",
1010
props: {
11-
printful: {
12-
type: "app",
13-
app: "printful",
14-
},
15-
recipientName: {
11+
printful,
12+
storeId: {
1613
propDefinition: [
1714
printful,
18-
"recipientName",
15+
"storeId",
1916
],
2017
},
21-
recipientAddress1: {
22-
propDefinition: [
23-
printful,
24-
"recipientAddress1",
25-
],
18+
externalId: {
19+
label: "External ID",
20+
description: "Order ID from the external system",
21+
type: "string",
22+
optional: true,
2623
},
27-
recipientCity: {
28-
propDefinition: [
29-
printful,
30-
"recipientCity",
31-
],
24+
recipientName: {
25+
label: "Recipient Name",
26+
description: "The recipient full name",
27+
type: "string",
3228
},
33-
recipientState: {
34-
propDefinition: [
35-
printful,
36-
"recipientState",
37-
],
29+
recipientCompanyName: {
30+
label: "Recipient Company Name",
31+
description: "The recipient company name",
32+
type: "string",
33+
optional: true,
3834
},
39-
recipientZip: {
40-
propDefinition: [
41-
printful,
42-
"recipientZip",
43-
],
35+
address1: {
36+
label: "Address 1",
37+
description: "The address 1",
38+
type: "string",
4439
},
45-
recipientCountry: {
46-
propDefinition: [
47-
printful,
48-
"recipientCountry",
49-
],
40+
address2: {
41+
label: "Address 2",
42+
description: "The address 2",
43+
type: "string",
44+
optional: true,
5045
},
51-
shippingMethod: {
52-
propDefinition: [
53-
printful,
54-
"shippingMethod",
55-
],
46+
city: {
47+
label: "City",
48+
description: "The city",
49+
type: "string",
5650
},
57-
orderItems: {
58-
propDefinition: [
59-
printful,
60-
"orderItems",
61-
],
51+
stateCode: {
52+
label: "State Code",
53+
description: "The state code. E.g. `SC`",
54+
type: "string",
6255
},
63-
recipientAddress2: {
64-
propDefinition: [
65-
printful,
66-
"recipientAddress2",
67-
],
56+
countryCode: {
57+
label: "Country Code",
58+
description: "The country code. E.g. `BR`",
59+
type: "string",
60+
reloadProps: true,
61+
},
62+
taxNumber: {
63+
label: "Tax Number",
64+
description: "TAX number (`optional`, but in case of Brazil country this field becomes `required` and will be used as CPF/CNPJ number)",
65+
type: "string",
6866
optional: true,
6967
},
70-
orderNotes: {
71-
propDefinition: [
72-
printful,
73-
"orderNotes",
74-
],
68+
zip: {
69+
label: "ZIP/Postal Code",
70+
description: "The ZIP/postal code. E.g. `89221525`",
71+
type: "string",
72+
reloadProps: true,
73+
},
74+
phone: {
75+
label: "Phone",
76+
description: "The phone number",
77+
type: "string",
7578
optional: true,
7679
},
77-
orderMetadata: {
78-
propDefinition: [
79-
printful,
80-
"orderMetadata",
81-
],
80+
email: {
81+
label: "Email",
82+
description: "The email",
83+
type: "string",
84+
optional: true,
85+
},
86+
giftSubject: {
87+
label: "Gift Subject",
88+
description: "Gift message title",
89+
type: "string",
8290
optional: true,
8391
},
92+
giftMessage: {
93+
label: "Gift Message",
94+
description: "Gift message text",
95+
type: "string",
96+
optional: true,
97+
},
98+
items: {
99+
label: "Items",
100+
description: "Array of items in the order. E.g. `[ { \"id\": 1, \"variant_id\": 2, \"quantity\": 3, \"price\": \"13.60\", \"retail_price\": \"9.90\", \"name\": \"Beauty Poster\", \"product\": { \"product_id\": 301, \"variant_id\": 500, \"name\": \"Red T-Shirt\" }, \"files\": [{\"url\": \"https://file.com/060b204a37f.png\"}] } ]`",
101+
type: "string",
102+
},
103+
},
104+
additionalProps(props) {
105+
props.taxNumber.optional = this.countryCode != "BR";
106+
return {};
84107
},
85108
async run({ $ }) {
86109
const response = await this.printful.createOrder({
87-
recipientName: this.recipientName,
88-
recipientAddress1: this.recipientAddress1,
89-
recipientAddress2: this.recipientAddress2,
90-
recipientCity: this.recipientCity,
91-
recipientState: this.recipientState,
92-
recipientZip: this.recipientZip,
93-
recipientCountry: this.recipientCountry,
94-
shippingMethod: this.shippingMethod,
95-
orderItems: this.orderItems,
96-
orderNotes: this.orderNotes,
97-
orderMetadata: this.orderMetadata,
110+
$,
111+
headers: {
112+
"X-PF-Store-Id": this.storeId,
113+
},
114+
data: {
115+
external_id: this.externalId,
116+
shipping: "STANDARD",
117+
recipient: {
118+
name: this.recipientName,
119+
company: this.recipientCompanyName,
120+
address1: this.address1,
121+
address2: this.address2,
122+
city: this.city,
123+
state_code: this.stateCode,
124+
country_code: this.countryCode,
125+
zip: this.zip,
126+
phone: this.phone,
127+
email: this.email,
128+
tax_number: this.taxNumber,
129+
},
130+
gift: {
131+
subject: this.giftSubject,
132+
message: this.giftMessage,
133+
},
134+
items: parseObject(this.items),
135+
},
98136
});
99-
$.export("$summary", `Created order ${response.id}`);
137+
138+
if (response) {
139+
$.export("$summary", `Successfully created order with id ${response.result.id}`);
140+
}
141+
100142
return response;
101143
},
102144
};

components/printful/actions/update-product/update-product.mjs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import printful from "../../printful.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "printful-update-product",
66
name: "Update Product",
7-
description: "Updates an existing product in your Printful store. [See the documentation](https://developers.printful.com/docs/)",
8-
version: "0.0.{{ts}}",
7+
description: "Updates an existing product in your Printful store. [See the documentation](https://developers.printful.com/docs/#tag/Products-API/operation/updateSyncProduct)",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
printful,
12-
productId: {
12+
storeId: {
1313
propDefinition: [
1414
printful,
15-
"productId",
15+
"storeId",
1616
],
1717
},
18-
updateFields: {
18+
productId: {
1919
propDefinition: [
2020
printful,
21-
"updateFields",
21+
"productId",
22+
({ storeId }) => ({
23+
storeId,
24+
}),
2225
],
2326
},
27+
alert: {
28+
type: "alert",
29+
alertType: "warning",
30+
content: `Please note that in the request body you only need to specify the fields that need to be changed.
31+
\nFurthermore, if you want to update existing sync variants, then in the sync variants array you must specify the IDs of all existing sync variants.
32+
\nAll omitted existing sync variants will be deleted. All new sync variants without an ID will be created.`,
33+
},
34+
syncProduct: {
35+
type: "object",
36+
label: "Sync Product",
37+
description: "Information about the SyncProduct. **Example: {\"external_id\": \"4235234213\", \"name\": \"T-shirt\", \"thumbnail\": \"http://your-domain.com/path/to/thumbnail.png\", \"is_ignored\": true}**",
38+
optional: true,
39+
},
40+
syncVariants: {
41+
type: "string[]",
42+
label: "Sync Variants",
43+
description: "Information about the Sync Variants. **Example: [{\"external_id\": \"12312414\", \"variant_id\": 3001, \"retail_price\": \"29.99\", \"is_ignored\": true, \"sku\": \"SKU1234\", \"files\": [{ \"type\": \"default\", \"url\": \"​https://www.example.com/files/tshirts/example.png\", \"options\": [{ \"id\": \"template_type\", \"value\": \"native\" }], \"filename\": \"shirt1.png\", \"visible\": true }], \"options\": [{ \"id\": \"embroidery_type\", \"value\": \"flat\" }], \"availability_status\": \"active\" }]**",
44+
optional: true,
45+
},
2446
},
2547
async run({ $ }) {
48+
2649
const response = await this.printful.updateProduct({
50+
$,
51+
headers: {
52+
"X-PF-Store-Id": this.storeId,
53+
},
2754
productId: this.productId,
28-
updateFields: this.updateFields,
55+
data: {
56+
sync_product: parseObject(this.syncProduct),
57+
sync_variants: parseObject(this.syncVariants),
58+
},
2959
});
3060
$.export("$summary", `Updated product ${this.productId}`);
3161
return response;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 100;

0 commit comments

Comments
 (0)