-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(oauth): add client credentials example * Added section for request Added section for working with connection#request() This includes information on how to use the API as well as a number of examples There are a large number of github issues related to this use-case, so hopefully this PR will reduce the number of issues/questions that people have in the future * Fix Salesforrce typo * chore: doc HTTP headers opts * chore: add cors section * chore: improve query builder docs * chore: update request examples * Update src/partials/document/cors.html.md Co-authored-by: Steve Hetzel <[email protected]> --------- Co-authored-by: Austin Turner <[email protected]> Co-authored-by: Andrew Plummer <[email protected]> Co-authored-by: Steve Hetzel <[email protected]>
- Loading branch information
1 parent
420013d
commit f54f96d
Showing
7 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## CORS | ||
|
||
If you're getting CORS-related errors when using jsforce in the browser it might be that the API being used doesn't support CORS, see: | ||
https://help.salesforce.com/s/articleView?id=sf.extend_code_cors.htm&type=5 | ||
|
||
For those cases you'll need to use the `jsforce-ajax-proxy` proxy server, check the README for setup instructions: | ||
https://github.com/jsforce/jsforce-ajax-proxy/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
--- | ||
|
||
## Request | ||
|
||
Make REST api calls to APIs that are not explicitly supported by JSForce. | ||
|
||
### Setting the URL | ||
|
||
The Endpoint URL can be in one of the following formats: | ||
|
||
- Absolute URL: `https://na1.salesforce.com/services/data/v32.0/sobjects/Account/describe`. | ||
- Relative path from root: `/services/data/v32.0/sobjects/Account/describe`. | ||
- Relative path from version root: `/sobjects/Account/describe`. | ||
- This is only supported if you have explicitly set a default version. | ||
|
||
### Making Requests | ||
|
||
You can use `Connection.request()` to make api requests. | ||
|
||
For GET requests, you can pass in a string URL. | ||
|
||
```javascript | ||
/* @interactive */ | ||
const res = await conn.request('/services/data/v47.0/ui-api/object-info'); | ||
console.log(res) | ||
``` | ||
|
||
If you prefer to use callbacks instead of promises, pass a callback as the second parameter. | ||
|
||
```javascript | ||
const res = await conn.request('/services/data/v47.0/ui-api/object-info'); | ||
console.log(res) | ||
``` | ||
|
||
For other HTTP methods, you can pass an object to the request method. Ensure that you serialize the body of the request. | ||
|
||
```javascript | ||
/* @interactive */ | ||
// Bulk API 2.0 - Query | ||
const requestBody = { | ||
operation: 'query', | ||
query: 'SELECT Id, Name FROM Account LIMIT 1000', | ||
}; | ||
|
||
const res = await conn | ||
.request({ | ||
method: 'POST', | ||
url: '/services/data/v47.0/jobs/query', | ||
body: JSON.stringify(requestBody), | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
console.log(res) | ||
``` | ||
|
||
#### Request Helper Methods | ||
|
||
In addition to `Connection.request()`, JSForce provides the following helper methods that can also be used: | ||
|
||
- `Connection.requestGet()` | ||
- `Connection.requestPatch()` | ||
- `Connection.requestPost()` | ||
- `Connection.requestPut()` | ||
- `Connection.requestDelete()` | ||
|
||
For `requestPatch`, `requestPost` and `requestPut`, these will be serialized automatically and the `content-type` will be set to `application/json`. | ||
|
||
```javascript | ||
/* @interactive */ | ||
const requestBody = { | ||
operation: 'query', | ||
query: 'SELECT Id, Name FROM Account LIMIT 1000', | ||
}; | ||
|
||
const res = await conn.requestPost('/services/data/v47.0/jobs/query', requestBody); | ||
console.log(res); | ||
``` | ||
|
||
#### Request HTTP Options | ||
|
||
All request methods allow setting HTTP options to be passed to the HTTP request. | ||
|
||
| Name | Type | Description | | ||
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| responseType | string | overrides the content-type from the response to change how the response is parsed. Valid values are `text/xml`, `application/xml`, `application/json`, `text/csv`. If you do not want JSForce to auto-parse the response, set this to any other value, e.x. `text`. | | ||
| noContentResponse | any | Alternative response when no content returned in response (= HTTP 204) | | ||
| transport | Transport | Transport for http api - you should not need to set this option. | | ||
|
||
If you would like to opt-out of parsing, you can set the `responseType` to text. This is useful if you want the raw response from Salesforce instead of having the results automatically parsed. | ||
|
||
```javascript | ||
// Get raw CSV data instead of allowing JSForce to parse the CSV to JSON | ||
const res = await conn.requestGet('/services/data/v47.0/jobs/query/7502J00000LYZC4QAP/results', { responseType: 'text' }); | ||
console.log(res); | ||
``` |