Skip to content

Commit e2a0cea

Browse files
committed
[Salesforce] Knowledge new action components
1 parent 24f033c commit e2a0cea

File tree

5 files changed

+251
-7
lines changed

5 files changed

+251
-7
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import app from "../../salesforce_rest_api.app.mjs";
2+
3+
export default {
4+
key: "salesforce_rest_api-get-knowledge-articles",
5+
name: "Get Knowledge Articles",
6+
description: "Get a page of online articles for the given language and category through either search or query. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_rest_retrieve_article_list.htm)",
7+
version: "0.0.6",
8+
type: "action",
9+
props: {
10+
app,
11+
q: {
12+
type: "string",
13+
label: "Search Term",
14+
description: "Performs an SOSL search. If this property is not set, an SOQL query runs. The characters `?` and `*` are used for wildcard searches. The characters `(`, `)`, and `\"` are used for complex search terms. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm).",
15+
optional: true,
16+
},
17+
channel: {
18+
type: "string",
19+
label: "Channel",
20+
description: "Where articles are visible (App, Pkb, Csp, Prm).",
21+
optional: true,
22+
options: [
23+
{
24+
label: "Internal Knowledge App",
25+
value: "App",
26+
},
27+
{
28+
label: "Public Knowledge Base",
29+
value: "Pkb",
30+
},
31+
{
32+
label: "Customer Portal",
33+
value: "Csp",
34+
},
35+
{
36+
label: "Partner Portal",
37+
value: "Prm",
38+
},
39+
],
40+
},
41+
language: {
42+
type: "string",
43+
label: "Language",
44+
description: "The language code. Defaults to `en-US`.",
45+
optional: true,
46+
},
47+
categories: {
48+
type: "string",
49+
label: "Categories",
50+
description: "This should be a map in json format `{\"group1\": \"category1\", \"group2\": \"category2\", ...}`. It must be unique in each group:category pair, otherwise you get `ARGUMENT_OBJECT_PARSE_ERROR`. There is a limit of three data category conditions, otherwise you get `INVALID_FILTER_VALUE`.",
51+
optional: true,
52+
},
53+
queryMethod: {
54+
type: "string",
55+
label: "Query Method",
56+
description: "Only valid when categories are specified, defaults to `ABOVE_OR_BELOW`.",
57+
optional: true,
58+
options: [
59+
"AT",
60+
"BELOW",
61+
"ABOVE",
62+
"ABOVE_OR_BELOW",
63+
],
64+
},
65+
sort: {
66+
type: "string",
67+
label: "Sort By",
68+
description: "Field to sort results by. Defaults to `LastPublishedDate` for query and relevance for search",
69+
optional: true,
70+
options: [
71+
"LastPublishedDate",
72+
"CreatedDate",
73+
"Title",
74+
"ViewScore",
75+
],
76+
},
77+
},
78+
methods: {
79+
getKnowledgeArticles(args = {}) {
80+
const { app } = this;
81+
return app._makeRequest({
82+
url: `${app._baseApiVersionUrl()}/support/knowledgeArticles`,
83+
...args,
84+
});
85+
},
86+
async paginate({
87+
requester,
88+
requesterArgs,
89+
resultsKey = "articles",
90+
maxRequests = 3,
91+
pageSize = 100,
92+
} = {}) {
93+
let allItems = [];
94+
let currentPage = 1;
95+
let hasMore = true;
96+
97+
while (hasMore && currentPage <= maxRequests) {
98+
const response = await requester({
99+
...requesterArgs,
100+
params: {
101+
...requesterArgs?.params,
102+
pageSize,
103+
pageNumber: currentPage,
104+
},
105+
});
106+
107+
const items = response[resultsKey];
108+
if (items?.length) {
109+
allItems = [
110+
...allItems,
111+
...items,
112+
];
113+
}
114+
115+
hasMore = !!response.nextPageUrl;
116+
currentPage++;
117+
}
118+
119+
return allItems;
120+
},
121+
},
122+
async run({ $ }) {
123+
const {
124+
app,
125+
paginate,
126+
getKnowledgeArticles,
127+
q,
128+
channel,
129+
language,
130+
categories,
131+
queryMethod,
132+
sort,
133+
} = this;
134+
135+
const items = await paginate({
136+
resultsKey: "articles",
137+
requester: getKnowledgeArticles,
138+
requesterArgs: {
139+
$,
140+
headers: {
141+
...app._makeRequestHeaders(),
142+
"Accept": "application/json",
143+
"Accept-Language": language || "en-US",
144+
},
145+
params: {
146+
q,
147+
channel,
148+
categories,
149+
queryMethod,
150+
sort,
151+
},
152+
},
153+
});
154+
155+
$.export("$summary", `Successfully fetched \`${items.length}\` articles`);
156+
157+
return items;
158+
},
159+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import app from "../../salesforce_rest_api.app.mjs";
2+
3+
export default {
4+
key: "salesforce_rest_api-get-knowledge-data-category-details",
5+
name: "Get Knowledge Data Category Details",
6+
description: "Fetch details of a specific data category and its child categories. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_rest_retrieve_data_category_details.htm)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
sObjectName: {
12+
type: "string",
13+
label: "sObject Name",
14+
description: "The sObject name (must be 'KnowledgeArticleVersion').",
15+
default: "KnowledgeArticleVersion",
16+
options: [
17+
"KnowledgeArticleVersion",
18+
],
19+
},
20+
groupName: {
21+
type: "string",
22+
label: "Group Name",
23+
description: "The name of the data category group.",
24+
},
25+
categoryName: {
26+
type: "string",
27+
label: "Category Name",
28+
description: "The name of the data category.",
29+
},
30+
},
31+
async run({ $ }) {
32+
const {
33+
sObjectName, groupName, categoryName,
34+
} = this;
35+
36+
const response = await this.app._makeRequest({
37+
url: `${this.app._baseApiVersionUrl()}/support/dataCategoryGroups/${groupName}/dataCategories/${categoryName}`,
38+
params: {
39+
sObjectName,
40+
},
41+
});
42+
43+
$.export("$summary", `Successfully fetched details for category '${categoryName}' in group '${groupName}'`);
44+
return response.data;
45+
},
46+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import app from "../../salesforce_rest_api.app.mjs";
2+
3+
export default {
4+
key: "salesforce_rest_api-get-knowledge-data-category-groups",
5+
name: "Get Knowledge Data Category Groups",
6+
description: "Fetch data category groups visible to the current user. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_rest_retrieve_data_category_groups.htm)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
sObjectName: {
12+
type: "string",
13+
label: "sObject Name",
14+
description: "The sObject name (must be 'KnowledgeArticleVersion').",
15+
default: "KnowledgeArticleVersion",
16+
options: [
17+
"KnowledgeArticleVersion",
18+
],
19+
},
20+
topCategoriesOnly: {
21+
type: "boolean",
22+
label: "Top Categories Only",
23+
description: "Return only top-level categories if true, entire tree if false.",
24+
default: true,
25+
},
26+
},
27+
async run({ $ }) {
28+
const {
29+
sObjectName, topCategoriesOnly,
30+
} = this;
31+
32+
const response = await this.app._makeRequest({
33+
url: `${this.app._baseApiVersionUrl()}/support/dataCategoryGroups`,
34+
params: {
35+
sObjectName,
36+
topCategoriesOnly,
37+
},
38+
});
39+
40+
$.export("$summary", `Successfully fetched ${response.data.categoryGroups?.length || 0} data category groups`);
41+
return response.data;
42+
},
43+
};

components/salesforce_rest_api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/salesforce_rest_api",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "Pipedream Salesforce (REST API) Components",
55
"main": "salesforce_rest_api.app.mjs",
66
"keywords": [

pnpm-lock.yaml

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)