2

I am using the Firebase node.js admin sdk to create user accounts via a csv importer with custom uids. This all works fine. On succesfull creation of the account I would like to update a database reference. However whenever the function loops through to create the entries in the db it fails with the message

Uncaught Error: Firebase.child failed: First argument was an invalid path: "contractors/jk116734s". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"

enter image description here

as you can see in the logged message above the path doesn't contain any of those unwanted characters and the path is not empty. Strangely it does update one record in the db but all the others fail. The path "contractors/jk116734s" I am also logging all the paths and none are undefined or containing invalid characters. The jk***** part of the urls are all unique fyi.

Here is my function that gets called on each succesfull account creation.

function createDbEtnryForUser(index, contractorData) {

    var ni = contractorData.ni;
    var path = "contractors/" + ni
    console.log(path);      
    databaseRoot.ref(path).update(contractorData);

    databaseRoot.ref(path).once('value',function(snapshot) {

        $('#row-'+index).css({"background-color":"green", "color":"white"});

    });

}

also you can see one entry is getting created but the rest are not.

enter image description here

Weirdly if I don't use the custom uid and use the auto uids created by firebase all works fine. What I don't understand though is that all the accounts do get created with the custom uid and as you can see logged I am getting the custom uid back to use in the call to update.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Alex McPherson
  • 3,185
  • 3
  • 30
  • 41
  • What is the value of **ni**? – camden_kid Jul 06 '17 at 09:33
  • @camden_kid the value of NI is part of the url "contractor/jk116633i" the jk part of the url as shown in the logs. – Alex McPherson Jul 06 '17 at 09:34
  • And what is the value of **contractorData**? I've seen this problem before and I think there is something in that object that is the cause of the problem. For example, a field with an invalid character. – camden_kid Jul 06 '17 at 09:36
  • @camden_kid. the value of contractorData is a javascript object as shown in the contractors node screenshot. If I don't use that and just get it to update 1 value i.e index:false for example ignoring all the others its still fails. What I dont get is the console message stating the character use and as you can see there isnt anything illegal or whitespace or undefined. – Alex McPherson Jul 06 '17 at 09:40
  • I wonder if there isn't an invisible character in **ni**? – camden_kid Jul 06 '17 at 09:43
  • @camden_kid hummm yeah. How would I go about finding it if it does indeed contain something. I've double checked my csv and no dodgy characters even by looking at the raw file. What I dont get is it is creating x1 entry the rest fail. – Alex McPherson Jul 06 '17 at 09:47
  • https://stackoverflow.com/a/12793237/782358. Not sure why it's failing after the first time. Try it with simple hard coded mock data to see if you have the same problem. – camden_kid Jul 06 '17 at 09:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/148483/discussion-between-alex-mcpherson-and-camden-kid). – Alex McPherson Jul 06 '17 at 09:57

1 Answers1

3

It looks like there may be invisible characters in the value of ni. See this answer - stackoverflow.com/a/12793237/782358 - to display those characters:

You can use encodeURI for showing the hidden stuffs.

camden_kid
  • 12,591
  • 11
  • 52
  • 88
  • 1
    Spot on. In my csv the last item for each row was the uid and it had carriage returns which I have now removed and can confirm it's working perfectly. I am also guessing that the uid creation for the account is less fussy and does indeed create custom id as expected the key was in the revealing of the hidden characters as shown by your example for the database refs. Thanks a lot! – Alex McPherson Jul 06 '17 at 10:18