diff --git a/components/bluecart_api/actions/get-autocomplete/get-autocomplete.mjs b/components/bluecart_api/actions/get-autocomplete/get-autocomplete.mjs index e51a90c729df6..fd586e9a23741 100644 --- a/components/bluecart_api/actions/get-autocomplete/get-autocomplete.mjs +++ b/components/bluecart_api/actions/get-autocomplete/get-autocomplete.mjs @@ -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, @@ -31,7 +31,7 @@ export default { const response = await this.app.getAutocomplete({ $, params: { - searchTerm: this.searchTerm, + search_term: this.searchTerm, type: "autocomplete", }, }); diff --git a/components/bluecart_api/actions/get-categories/get-categories.mjs b/components/bluecart_api/actions/get-categories/get-categories.mjs index 350f61a0dcfac..7ebe0877b0065 100644 --- a/components/bluecart_api/actions/get-categories/get-categories.mjs +++ b/components/bluecart_api/actions/get-categories/get-categories.mjs @@ -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, @@ -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"); + 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; + } }, }; diff --git a/components/bluecart_api/actions/get-product/get-product.mjs b/components/bluecart_api/actions/get-product/get-product.mjs index 9eb5c005e599b..6a92f97f6a20d 100644 --- a/components/bluecart_api/actions/get-product/get-product.mjs +++ b/components/bluecart_api/actions/get-product/get-product.mjs @@ -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, diff --git a/components/bluecart_api/bluecart_api.app.mjs b/components/bluecart_api/bluecart_api.app.mjs index 647ad7d1d296a..c838f6f37e27c 100644 --- a/components/bluecart_api/bluecart_api.app.mjs +++ b/components/bluecart_api/bluecart_api.app.mjs @@ -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, + }); }, }, }; diff --git a/components/bluecart_api/package.json b/components/bluecart_api/package.json index 6b61b228c6326..5311a1e17e47d 100644 --- a/components/bluecart_api/package.json +++ b/components/bluecart_api/package.json @@ -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": [