Hii ,
i tried to update permissions through api (requests) with endpoint /api/permissions/graph . i hit by an error i posted my code at the end and the log details are
2022-06-07T10:21:54+05:30 DEBUG metabase.server.middleware.log PUT /api/permissions/graph 400 3.3 ms (0 DB calls)
{:viastrong text
[{:type clojure.lang.ExceptionInfo,
:message
"Cannot parse permissions graph because it is invalid: {:body {:revision 33, :groups {:2 {:7 {:data {:native "write", :schemas "all"}, :download {:native "full", :schemas "full"}, :data-model {:schemas "all"}, :details "yes"}, :1 {:data {:native "write", :schemas "all"}, :download {:native "full", :schemas "full"}, :data-model {:schemas "all"}, :details "yes"}, :6 {:data {:native "write", :schemas "all"}, :download {:native "full", :schemas "full"}, :data-model {:schemas "all"}, :details "yes"}}, :1 {:1 {:download {:native "full", :schemas "full"}}, :6 {:download {:schemas "full", :native "full"}}}, :5 {:7 {:data {:schemas "all"}}, :6 {:data {:schemas "all"}}, :1 {:data {:schemas "all"}}}}}} - failed: (contains? % :groups) spec: :metabase.api.permission-graph/data-permissions-graph\n",
:data
{:status-code 400,
:error
{:clojure.spec.alpha/problems
({:path [],
:pred (clojure.core/fn [%] (clojure.core/contains? % :groups)),
:val
{:body
{:revision 33,
:groups
{:2
{:7
{:data {:native "write", :schemas "all"},
:download {:native "full", :schemas "full"},
:data-model {:schemas "all"},
:details "yes"},
:1
{:data {:native "write", :schemas "all"},
:download {:native "full", :schemas "full"},
:data-model {:schemas "all"},
:details "yes"},
:6
{:data {:native "write", :schemas "all"},
:download {:native "full", :schemas "full"},
:data-model {:schemas "all"},
:details "yes"}},
:1 {:1 {:download {:native "full", :schemas "full"}}, :6 {:download {:schemas "full", :native "full"}}},
:5 {:7 {:data {:schemas "all"}}, :6 {:data {:schemas "all"}}, :1 {:data {:schemas "all"}}}}}},
:via [:metabase.api.permission-graph/data-permissions-graph],
:in []}),
:clojure.spec.alpha/spec :metabase.api.permission-graph/data-permissions-graph,
:clojure.spec.alpha/value
{:body
{:revision 33,
:groups
{:2
{:7
{:data {:native "write", :schemas "all"},
:download {:native "full", :schemas "full"},
:data-model {:schemas "all"},
:details "yes"},
:1
{:data {:native "write", :schemas "all"},
:download {:native "full", :schemas "full"},
:data-model {:schemas "all"},
:details "yes"},
:6
{:data {:native "write", :schemas "all"},
:download {:native "full", :schemas "full"},
:data-model {:schemas "all"},
:details "yes"}},
:1 {:1 {:download {:native "full", :schemas "full"}}, :6 {:download {:schemas "full", :native "full"}}},
:5 {:7 {:data {:schemas "all"}}, :6 {:data {:schemas "all"}}, :1 {:data {:schemas "all"}}}}}}}},
:at [metabase.api.permissions$fn__60512 invokeStatic "permissions.clj" 47]}],
:trace
**i took the permissions graph structure from developer tools network tab (payload)
and my code
**
url ='https://meta**********.com/api/permissions/graph'
headers = {"Content-Type": "application/json;charset=utf-8",'X-Metabase-Session': token}
payload ={"groups":{"1":{"1":{"download":{"native":"full","schemas":"full"}},
"6":{"download":{"schemas":"full","native":"full"}}},
"2":{"1":{"data":{"native":"write","schemas":"all"},"download":{"native":"full","schemas":"full"},"data-model":{"schemas":"all"},"details":"yes"},
"6":{"data":{"native":"write","schemas":"all"},"download":{"native":"full","schemas":"full"},"data-model":{"schemas":"all"},"details":"yes"},
"7":{"data":{"native":"write","schemas":"all"},"download":{"native":"full","schemas":"full"},"data-model":{"schemas":"all"},"details":"yes"}},
"5":{"6":{"data":{"native":"write","schemas":"none"}},"7":{"data":{"schemas":"all"}}}},"revision":37}
data= {'body':payload}
response = requests.put(url, headers=headers,json=data)
print("Status Code", response.status_code)
print("JSON Response ", response.json())
i am not able to understand is this bug or my code was wrong if my code wrong
please mention right way to do it
i hope i will get a reply
Thank you