Skip to content

Commit 66ec243

Browse files
committed
Added actions
1 parent a115429 commit 66ec243

File tree

7 files changed

+305
-89
lines changed

7 files changed

+305
-89
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import app from "../../bluecart_api.app.mjs";
2+
3+
export default {
4+
key: "bluecart_api-get-autocomplete",
5+
name: "Get Autocomplete",
6+
description: "Get autocomplete suggestions for the specified search term. [See the documentation](https://docs.trajectdata.com/bluecartapi/walmart-product-data-api/parameters/autocomplete)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
walmartDomain: {
17+
propDefinition: [
18+
app,
19+
"walmartDomain",
20+
],
21+
},
22+
searchTerm: {
23+
propDefinition: [
24+
app,
25+
"searchTerm",
26+
],
27+
description: "The search term to get autocomplete suggestions for",
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.app.getAutocomplete({
32+
$,
33+
params: {
34+
searchTerm: this.searchTerm,
35+
type: "autocomplete",
36+
},
37+
});
38+
$.export("$summary", "Successfully retrieved " + response.autocomplete_results.length + " suggestions");
39+
return response;
40+
},
41+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import app from "../../bluecart_api.app.mjs";
2+
3+
export default {
4+
key: "bluecart_api-get-categories",
5+
name: "Get Categories",
6+
description: "Get a list of categories related to the provided search term. [See the documentation](https://docs.trajectdata.com/bluecartapi/walmart-product-data-api/parameters/category)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
searchTerm: {
17+
propDefinition: [
18+
app,
19+
"searchTerm",
20+
],
21+
description: "The term used to search for categories",
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.getCategories({
26+
$,
27+
params: {
28+
search_term: this.searchTerm,
29+
},
30+
});
31+
$.export("$summary", "Successfully retrieved " + response.categories.length + " categories");
32+
return response;
33+
},
34+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../bluecart_api.app.mjs";
2+
3+
export default {
4+
key: "bluecart_api-get-product",
5+
name: "Get product",
6+
description: "Get product data from Walmart. [See the documentation](https://docs.trajectdata.com/bluecartapi/walmart-product-data-api/parameters/product)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
walmartDomain: {
17+
propDefinition: [
18+
app,
19+
"walmartDomain",
20+
],
21+
},
22+
url: {
23+
propDefinition: [
24+
app,
25+
"url",
26+
],
27+
},
28+
itemId: {
29+
propDefinition: [
30+
app,
31+
"itemId",
32+
],
33+
},
34+
},
35+
36+
async run({ $ }) {
37+
const response = await this.app.searchItem({
38+
$,
39+
params: {
40+
walmart_domain: this.walmartDomain,
41+
type: "product",
42+
item_id: this.itemId,
43+
url: this.url,
44+
},
45+
});
46+
47+
$.export("$summary", "Successfully retrieved data for the product with id: " + response.product.item_id);
48+
return response;
49+
},
50+
};
Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,71 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "bluecart_api",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
walmartDomain: {
9+
type: "string",
10+
label: "Walmart Domain",
11+
description: "The Walmart domain to target",
12+
options: constants.DOMAIN_OPTIONS,
13+
},
14+
url: {
15+
type: "string",
16+
label: "URL",
17+
description: "The Walmart product page URL to retrieve results from",
18+
optional: true,
19+
},
20+
searchTerm: {
21+
type: "string",
22+
label: "Search Term",
23+
description: "A search term used to find Walmart items",
24+
},
25+
itemId: {
26+
type: "string",
27+
label: "Item ID",
28+
description: "The Walmart Item ID to retrieve product details for. Not used if a URL is provided",
29+
optional: true,
30+
},
31+
},
532
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
33+
_baseUrl() {
34+
return "https://api.bluecartapi.com";
35+
},
36+
async _makeRequest(opts = {}) {
37+
const {
38+
$ = this,
39+
path,
40+
params,
41+
...otherOpts
42+
} = opts;
43+
return axios($, {
44+
...otherOpts,
45+
url: this._baseUrl() + path,
46+
params: {
47+
api_key: `${this.$auth.api_key}`,
48+
...params,
49+
},
50+
});
51+
},
52+
async getCategories(args = {}) {
53+
return this._makeRequest({
54+
path: "/categories",
55+
...args,
56+
});
57+
},
58+
async searchItem(args = {}) {
59+
return this._makeRequest({
60+
path: "/request",
61+
...args,
62+
});
63+
},
64+
async getAutocomplete(args = {}) {
65+
return this._makeRequest({
66+
path: "/request",
67+
...args,
68+
});
969
},
1070
},
11-
};
71+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
DOMAIN_OPTIONS: [
3+
"walmart.com",
4+
"walmart.ca",
5+
],
6+
};

components/bluecart_api/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/bluecart_api",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream BlueCart API Components",
55
"main": "bluecart_api.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
1518
}

0 commit comments

Comments
 (0)