Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "bluecart_api-get-autocomplete",
name: "Get Autocomplete",
description: "Get autocomplete suggestions for the specified search term. [See the documentation](https://docs.trajectdata.com/bluecartapi/walmart-product-data-api/parameters/autocomplete)",
version: "0.0.1",
version: "0.0.2",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand All @@ -31,7 +31,7 @@ export default {
const response = await this.app.getAutocomplete({
$,
params: {
searchTerm: this.searchTerm,
search_term: this.searchTerm,
type: "autocomplete",
},
});
Expand Down
37 changes: 28 additions & 9 deletions components/bluecart_api/actions/get-categories/get-categories.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "bluecart_api-get-categories",
name: "Get Categories",
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)",
version: "0.0.1",
version: "0.0.2",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand All @@ -22,13 +22,32 @@ export default {
},
},
async run({ $ }) {
const response = await this.app.getCategories({
$,
params: {
search_term: this.searchTerm,
},
});
$.export("$summary", "Successfully retrieved " + response.categories.length + " categories");
return response;
try {
const response = await this.app.getCategories({
$,
params: {
search_term: this.searchTerm,
},
});

$.export("$summary", "Successfully retrieved " + response.categories.length + " categories");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider validating response structure.

Line 33 directly accesses response.categories.length without checking if categories exists. While the API should return this structure on success, defensive coding would prevent potential runtime errors if the API response format changes.

Consider adding optional chaining:

-     $.export("$summary", "Successfully retrieved " + response.categories.length + " categories");
+     $.export("$summary", "Successfully retrieved " + (response.categories?.length ?? 0) + " categories");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$.export("$summary", "Successfully retrieved " + response.categories.length + " categories");
$.export("$summary", "Successfully retrieved " + (response.categories?.length ?? 0) + " categories");
🤖 Prompt for AI Agents
In components/bluecart_api/actions/get-categories/get-categories.mjs around line
33, the code directly reads response.categories.length which can throw if
categories is undefined; update the summary to safely handle missing or
non-array categories by using optional chaining or a default (e.g.,
response.categories?.length ?? 0) and/or verifying
Array.isArray(response.categories) before accessing length so the exported
summary never errors when the API response shape changes.

return response;

} catch (err) {
if (
err?.response?.status === 400 &&
err?.response?.data?.request_info?.message?.includes("No categories match")
) {
const message = err.response.data.request_info.message;

$.export("$summary", message);
return {
success: false,
categories: [],
message,
};
}
throw err;
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "bluecart_api-get-product",
name: "Get product",
description: "Get product data from Walmart. [See the documentation](https://docs.trajectdata.com/bluecartapi/walmart-product-data-api/parameters/product)",
version: "0.0.1",
version: "0.0.2",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
68 changes: 64 additions & 4 deletions components/bluecart_api/bluecart_api.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "bluecart_api",
propDefinitions: {},
propDefinitions: {
walmartDomain: {
type: "string",
label: "Walmart Domain",
description: "The Walmart domain to target",
options: constants.DOMAIN_OPTIONS,
},
url: {
type: "string",
label: "URL",
description: "The Walmart product page URL to retrieve results from",
optional: true,
},
searchTerm: {
type: "string",
label: "Search Term",
description: "A search term used to find Walmart items",
},
itemId: {
type: "string",
label: "Item ID",
description: "The Walmart Item ID to retrieve product details for. Not used if a URL is provided",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.bluecartapi.com";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
params,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
params: {
api_key: this.$auth.api_key,
...params,
},
});
},
async getCategories(args = {}) {
return this._makeRequest({
path: "/categories",
...args,
});
},
async searchItem(args = {}) {
return this._makeRequest({
path: "/request",
...args,
});
},
async getAutocomplete(args = {}) {
return this._makeRequest({
path: "/request",
...args,
});
},
},
};
2 changes: 1 addition & 1 deletion components/bluecart_api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/bluecart_api",
"version": "0.1.0",
"version": "0.1.1",
"description": "Pipedream BlueCart API Components",
"main": "bluecart_api.app.mjs",
"keywords": [
Expand Down
Loading