Skip to content

Commit

Permalink
Merge pull request #465 from OpenFn/464-salesforce-request-fn
Browse files Browse the repository at this point in the history
`salesforce` add `request()` function
  • Loading branch information
josephjclark authored Jan 30, 2024
2 parents 81158ae + 7b88cf1 commit c28cb8d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-cows-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/language-salesforce': minor
---

Add `request(path, opts, cb)` function
44 changes: 44 additions & 0 deletions packages/salesforce/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,50 @@ export function toUTF8(input) {
return anyAscii(input);
}

/**
* Send a HTTP request using connected session information.
*
* @example
* request('/actions/custom/flow/POC_OpenFN_Test_Flow', {
* method: 'POST',
* json: { inputs: [{}] },
* });
* @param {String} url - Relative or absolute URL to request from
* @param {Object} options - Request options
* @param {String} [options.method] - HTTP method to use. Defaults to GET
* @param {Object} [options.headers] - Object of request headers
* @param {Object} [options.json] - A JSON Object request body
* @param {String} [options.body] - HTTP body (in POST/PUT/PATCH methods)
* @param {Function} callback - A callback to execute once the request is complete
* @returns {Operation}
*/

export function request(path, options, callback = s => s) {
return async state => {
const { connection } = state;
const [resolvedPath, resolvedOptions] = newExpandReferences(
state,
path,
options
);
const { method = 'GET', json, body, headers } = resolvedOptions;

const requestOptions = {
url: resolvedPath,
method,
headers: json
? { 'content-type': 'application/json', ...headers }
: headers,
body: json ? JSON.stringify(json) : body,
};

const result = await connection.request(requestOptions);

const nextState = composeNextState(state, result);

return callback(nextState);
};
}
// Note that we expose the entire axios package to the user here.
import axios from 'axios';

Expand Down

0 comments on commit c28cb8d

Please sign in to comment.