Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http 400 error trying to query nexus from clojure #527

Open
bahulneel opened this issue Jul 9, 2023 · 2 comments
Open

Http 400 error trying to query nexus from clojure #527

bahulneel opened this issue Jul 9, 2023 · 2 comments

Comments

@bahulneel
Copy link

I have a very simple namespace:

(ns ....db.core
  (:require [fluree.db.api :as fdb]
            [clojure.edn :as edn]))

(def *config  (atom nil))

(def *conn  (atom nil))

(defn load-config
  ([]
   (load-config "./.config.edn"))
  ([file]
   (-> file
       slurp
       edn/read-string)))

(defn ledger
  ([]
   (ledger @*config))
  ([{:keys [:db/network :db/db]}]
   (println network db)
   (str network "/" db)) )

(defn connect
  ([]
   (connect @*config))
  ([{:keys [:db/url :db/keypair]}]
   (let [conn (fdb/connect url {:private (:private keypair)})]
     conn)))

(defn db
  []
  (let [ledger (ledger)]
    (println ledger)
    (fdb/db @*conn ledger)))

(defn init!
  []
  (reset! *config (load-config))
  (reset! *conn (connect)))

(comment
  (init!)
  @(fdb/query (db) {:select ["*"] 
                   :from "_collection"}))

with the following config

#:db{:url "https://api.dev.flur.ee:443", 
     :network "fluree", 
     :db "387028092977578", 
     :keypair {:private "***", 
               :public "022111162e2e558783f5f5603a926dd478faf29a23338d73449d70001f869c9d97"}}

when I eval the code in the comment I get:

clj꞉....db.core꞉> 
{:id "521bc562-0de5-4697-af5f-112cb593de81",
 :servers ["https://api.dev.flur.ee:443"],
 :state
 #<Atom@3abe18ff: 
   {:close? false, :health {}, :connected-to nil, :socket nil, :socket-id nil, :pending-req {}, :listeners {}}>,
 :req-chan
 #object[clojure.core.async.impl.channels.ManyToManyChannel 0x291f3c9 "clojure.core.async.impl.channels.ManyToManyChannel@291f3c9"],
 :sub-chan
 #object[clojure.core.async.impl.channels.ManyToManyChannel 0x221d794c "clojure.core.async.impl.channels.ManyToManyChannel@221d794c"],
 :pub-chan
 #object[clojure.core.async.impl.channels.ManyToManyChannel 0x591c0ae "clojure.core.async.impl.channels.ManyToManyChannel@591c0ae"],
 :group nil,
 :storage-read #function[fluree.db.connection/default-storage-read/fn--54657],
 :storage-list nil,
 :storage-write #function[fluree.db.connection/generate-connection/fn--54837],
 :storage-exists #function[fluree.db.connection/default-storage-read/fn--54657],
 :storage-rename nil,
 :storage-delete nil,
 :object-cache #function[fluree.db.connection/default-object-cache-fn/fn--54759],
 :async-cache #function[fluree.db.connection/default-async-cache-fn/fn--54763],
 :parallelism 4,
 :serializer {},
 :default-network nil,
 :transactor? false,
 :publish nil,
 :transact-handler nil,
 :tx-private-key nil,
 :tx-key-id nil,
 :meta nil,
 :add-listener #function[clojure.core/partial/fn--5908],
 :remove-listener #function[clojure.core/partial/fn--5908],
 :close #function[fluree.db.connection/generate-connection/close--54839],
 :memory false,
 :keep-alive nil,
 :keep-alive-fn nil}
clj꞉....db.core꞉> 
fluree 387028092977578
fluree/387028092977578
#error {
 :cause "xhttp error - https://api.dev.flur.ee:443/fdb/storage/fluree/387028092977578/root/000000000000001: 400 - error response"
 :data {:url "https://api.dev.flur.ee:443/fdb/storage/fluree/387028092977578/root/000000000000001", :error :xhttp/exception, :status 400}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "xhttp error - https://api.dev.flur.ee:443/fdb/storage/fluree/387028092977578/root/000000000000001: 400 - error response"
   :data {:url "https://api.dev.flur.ee:443/fdb/storage/fluree/387028092977578/root/000000000000001", :error :xhttp/exception, :status 400}
   :at [fluree.db.util.xhttp$format_error_response invokeStatic "xhttp.cljc" 73]}]
 :trace
 [[fluree.db.util.xhttp$format_error_response invokeStatic "xhttp.cljc" 73]
  [fluree.db.util.xhttp$format_error_response invoke "xhttp.cljc" 34]
  [fluree.db.util.xhttp$get$fn__30386 invoke "xhttp.cljc" 166]
  [org.httpkit.client$request$deliver_resp__29702$fn__29703 invoke "client.clj" 271]
  [org.httpkit.client$request$deliver_resp__29702 invoke "client.clj" 270]
  [org.httpkit.client$request$reify__29706 onSuccess "client.clj" 310]
  [org.httpkit.client.Handler run "RespListener.java" 42]
  [java.util.concurrent.Executors$RunnableAdapter call "Executors.java" 577]
  [java.util.concurrent.FutureTask run "FutureTask.java" 317]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1144]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 642]
  [java.lang.Thread run "Thread.java" 1589]]}
clj꞉touchpoint.db.core꞉> 

I followed the instructions here to create the key pair. and added the auth to the DB using the HTTP w/ API_KEY method.

@jakep36
Copy link

jakep36 commented Jul 13, 2023

Hi @bahulneel

What version of the fluree db library are you using to try and connect?

@bahulneel
Copy link
Author

I was the latest at the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants