Giter Site home page Giter Site logo

salesforce's Issues

Execution error (MalformedURLException) at java.net.URL/<init>

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?

NullPointerException on SFDC API errors.

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"})

Need to specify hostname in config

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.