Skip to content

Commit 2884b04

Browse files
authored
Introduce baseURL in Raw Request Action axios config
1 parent 33b5b96 commit 2884b04

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## 2.8.2 (February 02, 2023)
1+
## 2.8.3 (February 27, 2024)
2+
* The component interface has not changed. This is a technical enhancement! Introduced baseURL parameter in the `Raw Request` Action's configuration of the axios library. Refer to the [Readme](README.md#raw-request) for the details.
3+
It will not affect any of the existing integration. Instead, it gives more flexibility allowing to call other REST endpoints than the standard `/services/data` [(#82)](https://github.com/elasticio/salesforce-component-v2/issues/82)
4+
5+
## 2.8.2 (February 02, 2024)
26
* Fixed bug when component didn't use `replayId` after error in `Subscribe to PubSub` trigger
37

48
## 2.8.1 (December 28, 2023)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,13 @@ Empty object will be returned, if query doesn't find any data.
358358

359359
### Raw Request
360360

361+
This function executes a custom REST API call request. By default, the service called is `/services/data`, which encompasses most of the services provided by Salesforce.
362+
Alternatively, you can call any other services, such as `/services/apexrest`, by specifying the full URL instead of a relative one.
363+
361364
#### Input Metadata
362365
* HTTP Verb - Allowed values GET, POST, PUT, PATCH, DELETE, HEAD, Required. HTTP verb to use in the request.
366+
* To call services based on the `/services/data` endpoint, you can utilize a relative path, for instance, `query/?q=SELECT+Id,Name+FROM+Account`. This automatically constructs the URL as follows: `https://{your_instance}.salesforce.com/services/data/{SALESFORCE_API_VERSION}/query/?q=SELECT+Id,Name+FROM+Account`
367+
* For calling other services like `/services/apexrest`, provide **the full URL**, such as `https://{your_instance}.salesforce.com/services/apexrest/myApexClass`
363368
* Path - String, Required. Use a relative path to make a request (for a list of all types of objects - `sobjects`, e.g., to list the type of objects Account - `sobjects/account`). Since Salesforce sends the endpoint that must be called dynamically, there is no need to enter the base URL like this - `https://{INSTANCE_NAME}.salesforce.com/services/data/v{SALESFORCE_API_VERSION}/sobjects/{SALESFORCE_OBJECT}`. Instead, you should use a relative path - `sobjects/{SALESFORCE_OBJECT}`.
364369
* Request Body - Object, Optional. Body to attach to the HTTP Request
365370

component.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"title": "Salesforce v2",
33
"description": "Customer relationship management (CRM) software & cloud computing from the leader in CRM solutions for businesses large & small.",
44
"docsUrl": "https://github.com/elasticio/salesforce-component-v2",
5-
"url": "http://www.salesforce.com/",
6-
"version": "2.8.2",
5+
"url": "https://www.salesforce.com/",
6+
"version": "2.8.3",
77
"authClientTypes": [
88
"oauth2"
99
],
@@ -703,4 +703,4 @@
703703
}
704704
}
705705
}
706-
}
706+
}

lib/actions/rawRequest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ async function processAction(msg, cfg) {
4343
logger.info('Trying to call method %s', method);
4444
const basePath = `/services/data/v${SALESFORCE_VERSION}/`;
4545
const resourcePath = (path.trim().charAt(0) === '/') ? path.trim().slice(1) : path.trim();
46-
const rawRequestPath = `${instanceUrl}${basePath}${resourcePath}`;
4746
const lowerCasedMethod = method.toLowerCase();
4847
const rawRequestConfig = {
48+
baseURL: `${instanceUrl}${basePath}`,
4949
method: lowerCasedMethod,
50-
url: rawRequestPath,
50+
url: resourcePath,
5151
headers: {
5252
Authorization: `Bearer ${accessToken && accessToken.replace(/"|'/g, '')}`,
5353
'Content-Type': 'application/json',

spec/actions/rawRequest.spec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
const processAction = require('../../lib/actions/rawRequest');
1010

1111
describe('Raw request test', () => {
12-
describe('Should succeed with method GET resource sobjects', () => {
12+
describe('Should succeed with method GET, relative URL, resource sobjects', () => {
1313
it('Retrieves the list of queryable sobjects', async () => {
1414
const testCfg = { ...defaultCfg };
1515
const msg = { body: { method: 'GET', path: 'sobjects' } };
@@ -29,6 +29,29 @@ describe('Raw request test', () => {
2929
});
3030
});
3131

32+
describe('Should succeed with method GET, absolute URL, resource apexrest', () => {
33+
it('Retrieves the list of queryable sobjects', async () => {
34+
const testCfg = { ...defaultCfg };
35+
const msg = {
36+
body: {
37+
method: 'POST',
38+
path: `${testsCommon.instanceUrl}/services/apexrest/echoRequest`,
39+
body: {
40+
text: 'fool',
41+
},
42+
},
43+
};
44+
45+
fetchToken();
46+
const scope = nock(testsCommon.instanceUrl)
47+
.post('/services/apexrest/echoRequest')
48+
.reply(200, 'No, you are fool');
49+
const result = await processAction.process.call(getContext(), msg, testCfg);
50+
expect(result.body).to.have.eql('No, you are fool');
51+
scope.done();
52+
});
53+
});
54+
3255
describe('Should succeed with method POST request create record', () => {
3356
it('Retrieves the list of limits', async () => {
3457
const testCfg = { ...defaultCfg };

0 commit comments

Comments
 (0)