Registry / crm / fetch-salesforce

fetch-salesforce

JSON →
library2.0.1jsnpmunverified

A client for the Salesforce REST API using the Fetch API. Current stable version is 2.0.1. The library is maintained and designed for React Native but works in any environment supporting fetch. It provides a simple interface for CRUD operations, queries, and authentication. Version 2.0 introduces breaking changes, including requiring fetch to be defined globally. Differentiators: lightweight, no heavy dependencies, TypeScript-first with full typings.

npm install fetch-salesforce
INSTALL
IMPORT
SIG · FETCH-SALESFORCE
F
fetch-salesforce
crmjavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FetchSalesforce
import { FetchSalesforce } from 'fetch-salesforce'
const FetchSalesforce = require('fetch-salesforce')
The package is ESM-only; CommonJS require will fail.
SalesforceOptions
import { SalesforceOptions } from 'fetch-salesforce'
import SalesforceOptions from 'fetch-salesforce'
This is a named export, not a default export.
fetchSObject
fetchSalesforce.fetchSObject.insert('Account', { Name: 'My Account' })
fetchSObject.insert('Account', { Name: 'My Account' })
fetchSObject is a property of FetchSalesforce instance, not a standalone import.
fetchQuery
fetchSalesforce.fetchQuery.query('SELECT ID FROM Account LIMIT 10')
import { fetchQuery } from 'fetch-salesforce'
fetchQuery is accessed via the FetchSalesforce instance.

Shows how to instantiate the client with required options and run a simple SOQL query.

import { SalesforceOptions, FetchSalesforce } from 'fetch-salesforce'; const options: SalesforceOptions = { clientID: process.env.SF_CLIENT_ID ?? '', authorizationServiceURL: process.env.SF_AUTH_URL ?? 'https://login.salesforce.com/services/oauth2/authorize', tokenServiceURL: process.env.SF_TOKEN_URL ?? 'https://login.salesforce.com/services/oauth2/token', redirectUri: process.env.SF_REDIRECT_URI ?? 'https://localhost:3000/callback', apiVersion: 58.0, logLevel: 'INFO', }; const sf = new FetchSalesforce(options); async function run() { const result = await sf.fetchQuery.query('SELECT Id, Name FROM Account LIMIT 2'); console.log('Query result:', JSON.stringify(result, null, 2)); } run().catch(console.error);
Debug
Known issues
breakingVersion 2.0 requires fetch to be globally defined; it no longer bundles a fetch polyfill.
fix
Use cross-fetch or ensure your environment provides fetch. See the 'My target doesn't support fetch' section in the README.
affects: >=2.0.0
breakingAll exports are now named; there is no default export. CommonJS require('fetch-salesforce') will fail.
fix
Use ES module imports: import { FetchSalesforce, SalesforceOptions } from 'fetch-salesforce'.
affects: >=2.0.0
deprecatedThe logLevel option with values 'DEBUG', 'INFO', 'WARN', 'ERROR' may be removed in future versions. Use numeric log levels instead.
fix
Use numeric log levels: 0 for DEBUG, 1 for INFO, 2 for WARN, 3 for ERROR.
affects: >=1.0.0
gotchaThe apiVersion option accepts a number (e.g., 39.0) but may be misinterpreted if passed as a string (e.g., '39.0').
fix
Always pass apiVersion as a number: apiVersion: 58.0
affects: >=1.0.0
gotchaWhen using OAuth, the redirectUri must match the one configured in your Salesforce connected app exactly, including trailing slashes.
fix
Ensure the redirectUri string matches the Salesforce connected app configuration exactly.
affects: >=1.0.0
gotchaThe library does not handle token refresh automatically; you must implement refresh logic in your application.
fix
Use a library like 'simple-oauth2' or implement a custom token refresh wrapper around FetchSalesforce.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'fetch-salesforce'
Package not installed or import path incorrect.
fix
Run 'npm install fetch-salesforce' or 'yarn add fetch-salesforce'. Ensure the import statement is correct.
TypeError: fetch is not a function
Global fetch is not defined in the runtime (e.g., Node.js <18 or React Native with missing polyfill).
fix
Install and import 'cross-fetch' polyfill or ensure the environment provides fetch.
TypeError: (0 , _fetchSalesforce.FetchSalesforce) is not a constructor
Using CommonJS require when the package is ESM-only.
fix
Switch to ES module import: import { FetchSalesforce } from 'fetch-salesforce'.
Cannot read properties of undefined (reading 'query')
Attempting to access fetchQuery before authenticating or without proper options.
fix
Ensure you have instantiated FetchSalesforce with valid options and completed OAuth flow.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
cross-fetchoptionalOptional polyfill/ponyfill for environments without fetch support (e.g., older Node).
Agent activity
31 hits · last 30 days
node
24
Resources