owainlewis / salesforce Goto Github PK
View Code? Open in Web Editor NEWA Clojure library for interacting with Salesforce.com
A Clojure library for interacting with Salesforce.com
Hi
While trying to setup a connection with Salesforce I ran into the following issue:
Execution error (MalformedURLException) at java.net.URL/ (URL.java:672).
no protocol: /services/data/v51.0/sobjects/Account
This is code that I used, and I got a warning and exception while loading it into the REPL
Connecting to local nREPL server...
nREPL server started on port 56447 on host localhost - nrepl://localhost:56447
Clojure 1.10.1
(ns mytest.core )
=> nil
(use 'salesforce.core)
WARNING: update already refers to: #'clojure.core/update in namespace: clj-http.client, being replaced by: #'clj-http.client/update
=> nil
(def config
{:client-id "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
:client-secret "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
:username "[email protected]"
:password "XXXXX"
:security-token ""
:login-host "test.salesforce.com"})
=> #'mytest.core/config
(def auth-info (auth! config))
Execution error (ExceptionInfo) at slingshot.support/stack-trace (support.clj:194).
clj-http: status 400
(set-version! (latest-version))
=> "51.0"
(defn foo
"I don't do a whole lot."
[]
(println "My First Salesforce connection!")
(so->all "Account" auth-info))
=> #'mytest.core/foo
(foo)
My First Salesforce connection!
Execution error (MalformedURLException) at java.net.URL/<init> (URL.java:672).
no protocol: /services/data/v51.0/sobjects/Account
Any thoughts on how I can resolve this?
Latest version of the library (1.0.2) is not available at clojars ( https://repo.clojars.org/salesforce/salesforce/ ), the latest one there is 1.0.1. Can you please publish the latest one there?
Currently salesforce.core/request
doesn't handle properly the case when SFDC API returns error.
There is try/catch
around clj-http.client/request but then parse-limit-info
crashes with NullPointerException
due to absence [:headers "sforce-limit-info"]
in the resp
.
Even when pass through the parse-limit-info
, the salesforce.core/request
returns nil
instead of SFDC error message since exception's :body
is already extracted.
Please consider the diff:
--- a/src/salesforce/core.clj
+++ b/src/salesforce/core.clj
@@ -1,6 +1,5 @@
(ns salesforce.core
(:require
- [clojure.string :as str]
[cheshire.core :as json]
[clj-http.client :as http]
[clojure.string :as str]
@@ -71,10 +70,10 @@
{:method method
:url full-url
:headers {"Authorization" (str "Bearer " (:access_token token))}}))
- (catch Exception e (:body (ex-data e))))]
- (-> (get-in resp [:headers "sforce-limit-info"]) ;; Record limit info in atom
- (parse-limit-info)
- ((partial reset! limit-info)))
+ (catch Exception e (ex-data e)))]
+ (some-> (get-in resp [:headers "sforce-limit-info"]) ;; Record limit info in atom
+ (parse-limit-info)
+ ((partial reset! limit-info)))
(-> resp
:body
(json/decode true))))
BEFORE
=> (sf/so->objects auth)
Execution error (NullPointerException) at (REPL:1).
null
AFTER
=> (sf/so->objects auth)
({:message "The REST API is not enabled for this Organization.", :errorCode "API_DISABLED_FOR_ORG"})
I have been told we need to use stempowered.my.salesforce.com not login.salesforce.com
Need to be able to pass in a hostname explicitly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.