Closed chulkilee closed 6 years ago
client = ExForce.build_client("
https://login.salesforce.com",
access_token: access_token,
api_version: "40.0"
)
The instance_url returned as the OAuth.Response struct is what needs to be passed into the client instead of something like "https://login.salesforce.com" or "https://test.salesforce.com" or an error like the following will occur.
iex> ExForce.query(client, "Select Id, Name FROM Account")
{:error,
{:no_default_port, :" https",
' https://test.salesforce.com/services/data/v41.0/query?q=Select+Id%2C+Name+FROM+Account'}}
Since the data is already available in the OAuth.Response struct, maybe the build_client/2 function can accept the OAuth.Response struct, a map, tuple, or another struct that contains the instance_url, and access_token.
EDIT: This works too
## Usage
{:ok, %{access_token: access_token, instance_url: instance_url}} = ExForce.OAuth.get_token(
"https://login.salesforce.com",
grant_type: "password",
client_id: "client_id",
client_secret: "client_secret",
username: "username",
password: "password"
)
client = ExForce.build_client("
instance_url,
access_token: access_token,
api_version: "40.0"
)
@MrDoops Thanks a lot for feedback!
First of all, the example code had a leading whitespaces to https://
.
Also I found that REST API call must be called on instance url, not login.salesforce.com
(or you will get following error:
{:error, [%{"errorCode" => "URL_NOT_RESET", "message" => "Destination URL not reset. The URL returned from login must be set"}]}
So, it should be actual instance_url
, not just login.salesforce.com
.
And I agree that it's better to let build_client/2
accept the map (compatible with ExForce.OAuthResponse
).
Pushed a commit for this (with some refactoring)
17