Hello all
Using the API (both REST and RPC), I’m trying to import users from a JSON file. However I only want to create new users if they do not already exist. I’m trying to figure out which is the most efficient way of checking whether a user (and more generically any record) exists.
I notice that the RPC method frappe.client.get does not throw an error when the record does not exist and returns a JSON object with a top-level key:value pair of “exc_type”:“DoesNotExistError”
curl -s -H "${cHA}" -H "${cHC}" -H "${cHT}" -G ${cUM}frappe.client.get -d 'doctype=User' -d 'name=Admin'
which returns
{"exc_type":"DoesNotExistError","_server_messages":"[\"{\\\"message\\\": \\\"User Admin not found\\\",...
and when the user does exist (eg Administrator, not Admin), the return then is also a JSON object but with a top level key of “message”.
{"message":{"name":"Administrator",...
Currently I use this differentiation on the top-level key to determine whether the record exists or not, before I invoke the REST call to create a new user, but it feels very convoluted and I somehow believe there should be a more efficient way of doing it.
What does the experts recommend?