I have an app and when a user creates an account it generates a uid for that user.
When the user continues to use the app and creates a card it will create a separate node under "cards" and generate a unique id for that card with a name and type of card. This is how I have done it
let card = ref.child("cards").childByAutoId()
card.setValue(["nickname": finalNickname, "type": finalType])
I am trying to link the nodes, I have been told to not put everything under one tree but to flatten it and have them be separate and then just link it.
This is what I have tried to do, with no success
ref.child("users").child((user?.uid)!).child("cards").child(card).setValue(true)
The problem that I am getting is that the .child(...) wants a String, and card is a FIRDatabaseReference.
Any ideas?
Your card variable is a FIRDatabaseReference. You're looking to get the key from it, so card.key:
ref.child("users").child((user?.uid)!).child("cards").child(card.key).setValue(true)
You could try this?
ref.child("users").child(user!.uid).child("cards").childByAutoId().setValue(["nickname": finalNickname, "type": finalType])
It is not really clear what you are exactly trying to do, could you provide more information
Related
I am an iOS app developer. Right now, I need my app to update his/her scores in the database (Firestore) when a user tabs a button.
I only know that it is possible to add new documents to the database according to the official doc: https://firebase.google.com/docs/firestore/quickstart#swift. But can I simply update one key-value pair within a document at a time?
For example, I have to add 10 points to the user with ID: 1234 if he/she clicks the correct button. So first of all, I need to read the data according to the unique ID, and catch his/her current points. Then put back the points plus 10.
It looks like Firestorage only allows users to upload an entire document once a time.
Swift code snippet is appreciated!
You can update a single or multiple fields in a document with the updateData call.
To atomically increment a numeric value can you can use the FieldValue.increment operation. From that last link comes this example:
washingtonRef.updateData([
"population": FieldValue.increment(Int64(50))
])
This code increments the population field in the document by 50, and leave other fields in the document unmodified.
Here is my workflow:
Person clicks on my ScheduleOnce link and schedules a meeting
Upon completing the ScheduleOnce booking form, the person clicks the done button
When this done button is clicked the person is redirected to a Node JS web app that displays an application page. This application page needs to be auto-populated with the information from the ScheduleOnce page.
Between step 2 and 3 is where Zapier comes in. I am trying to use Zapier to capture the data from the ScheduleOnce booking, which it is. Then I am trying to use a Zap to send that data to the page the person is redirected to, to auto-populate some of the fields.
I thought using the Code Javascript functionality would work but it does not. So then I was thinking about using the StoreClient option or the API. I am just confused on how to get the flow to work to access the data and auto-populate the fields on the next redirected page.
Some help would be greatly appreciated.
Here is the code I have for the Javascript option:
var store = StoreClient("Secret");
store
.setMany({firstName: inputData.firstName, lastName: inputData.lastName, email: inputData.email, mobilePhone: inputData.mobilePhone, otherPhone: inputData.otherPhone, businessWebsite: inputData.businessWebsite})
.then(function() {
return store.getMany('firstName', 'lastName', 'email', 'mobilePhone', 'otherPhone', 'businessWebsite');
})
.then(function() {
callback();
})
.catch(callback);
David here, from the Zapier Platform team. This is a cool use case and is probably possible. Something you need to remember is that Zapier is running totally separately from the user, so interaction will have to be indirect. Zapier can't redirect your user anywhere, it can just store data in response to a button push.
In your case you can skip everything after the setMany, since you're not trying to use the values in the zap; you just need to store them (and verify that action completed without errors).
var store = StoreClient("Secret");
store
.setMany({firstName: inputData.firstName, lastName: inputData.lastName, email: inputData.email, mobilePhone: inputData.mobilePhone, otherPhone: inputData.otherPhone, businessWebsite: inputData.businessWebsite})
.catch(callback);
You'll need to solve a couple of problems:
Speed. the user will reach your landing page before the zap completes (as it has to make a couple of HTTP round trips and execute code). You'll want to play them a 3 second loading gif, or put a waiting message and allow them to refresh the destination
Populating the page. I'm not sure what the nature of the destination is (best case scenario is that it's a server you control), but something will need to make an http request to store.zapier.com to retrieve the stored data and surface it in the view. This is easy if
Identifying the user. You'll need some way to identify the user getting redirected to the data you stored in StoreClient. If two users fill out the form in quick succession, the second one will currently overwrite the first. Plus, it seems to be semi-sensitive data that you don't just want available to anyone on your site. To that end, you'll probably want to store all of the data as a JSON string keyed by the user's email (or something else unique). That way, when I (the user) finish the form, I'm redirected to yoursite.com/landing?email=david#zapier.com, the backend knows to look for (the david#zapier.com key in store) and can render a view with the correct info.
To that end, I'd tweak the code to the following:
var store = StoreClient("Secret");
store
.set(inputData.email, JSON.stringify({firstName: inputData.firstName, lastName: inputData.lastName, email: inputData.email, mobilePhone: inputData.mobilePhone, otherPhone: inputData.otherPhone, businessWebsite: inputData.businessWebsite}))
.catch(callback);
Hope that points you in the right direction. You're working with a pretty complicated workflow, but I bet you can do it!
I am trying to figure out a way to get a list of each unique child in my Firebase Database & get a count of each unique child.
So for example if somebody entered Amazon 5 times an Hulu 2 times. I want to be able to know that. However, I don't want the user to know this.
I had a few ideas on how to do this.
Idea 1
Use Firebase's:
Answers.logCustomEvent...
However, I see two flaws with this idea.
Flaw 1: This wouldn't be useful for data that has already been entered.
Flaw 2: A user could enter Amason on accident and then changes it later to be the correct Amazon. I would get the incorrect entry..I could log changes but then I'd get bad data...or at least confusing data.
Idea 2
I could write a function inside of the app that could do this, but like I said. I don't need this functionality in the app for the user. I want it so I can know which sites I need to add functionality for first over ones that are seldom entered.
However, is it possible to have 2 apps that use the same database? So the main app is able to read and write data. While I could create a simple app that I wouldn't publish, only really use for myself that could Read the data but not write to it...
I tried to make my Database flat as I knew how..
When a user adds a service it doesn't go under the user node, I have a child called "services" and I just reference that service child in the "user" child.
So my database looks like this
cards
card uid 1
cardname: ""
services
service uid 1: true
services
service uid 1
serviceName: Amazon
serviceUrl: ""
service uid 2
serviceName: Amazon
users
... reference the card this user has access to
So to repeat the question.
I want to be able to know each unique serviceName and if there are duplicates of the same one..how many there are..
I don't need to know who created it or when..
you may have another table where you have objects with only 2 fields: serviceName and count.
So, everytime you have a new instance, you check if it already persists in your table and increment the count value, otherwise create a new row.
Users will not see that info.
And, yes, you can access one database from several apps. Just get clientID, trackingID, etc...
Right now, I'm generating unique IDs with childByAutoId(), but was wondering if there was a way to do this only generating numbers, no letters or other characters?
The reason is I need to be able to automatically send this key through imessage (part of how I send invites) and when it contains letters you're not able to automatically select and copy the key without copying the entire text message. With numbers only the key will be underlined and selectable.
Is there a way to either generate an ID with numbers only, or to selectively underline part of an iMessage with MFMessage in Swift?
Thanks!
I've need a similar option. When i create a new user; it will have a numberID which will be unique. I've tried .push() method which is for android, creates a uniqueID but with characters(letters) included. What i've done was something like this;
When i add a new user, i increment a value from different branch which is User2Key in this situation. And gave the value as key(parent) of newly added user.
When i delete or update a user, User2Key will be the same. If i add a new user then it will be incremented so every user will have uniqueID.
You can use a similar approach.
Hope this helps! Cheers!
Ok so Im already an affiliate of amazon. I'm dynamically generating links based on results from their API. Im trying to put the customer in front of a permission to add an item to their cart. I have this structure as an example:
http://www.amazon.com/gp/aws/cart/add.html?AssociateTag=your-tag-here-20&ASIN.1=B003IXYJYO&Quantity.1=2&ASIN.2=B0002KR8J4&Quantity.2=1&ASIN.3=B0002ZP18E&Quantity.3=1&ASIN.4=B0002ZP3ZA&Quantity.4=2&ASIN.5=B004J2JG6O&Quantity.5=1
This works great as long as Im selling amazon-only products. What Im trying to do is put them in front of the lowest price for that product (items that are being sold on amazon by other people/dealers).
I already have the lowest prices etc etc. The problem is structuring the link to get them there. Do any of you know the parameters in the url that I would add or at least a list of parameters I could sift through to find what Im looking for?
Also, if theres a way to just put the item in their cart as apposed to taking them to a permission to add to cart...that would be that much better!
Thanks in advance!
Please refer to the documentation for forming an associate URL:
https://webservices.amazon.com/paapi5/documentation/add-to-cart-form.html
The "Add to Cart" form enables you to add any number of items to a customer's shopping cart and send the customer to the Amazon retail website for completing the purchase. Some parameters are optional, but you must specify quantity and at least one of the following parameters: ASIN or OfferListingId. AssociateTag is a must for attribution. You can either use this Online Amazon Add To Cart Link Generator To Easily Generate Add To Cart Link Without writing attributes by yourself or you can do this manually just like this:
"ASIN.1=[ASIN]&Quantity.1=1&ASIN.2=[Another ASIN]&Quantity.2=10"
Your final Link May Look Like This:
https://www.amazon.in/gp/aws/cart/add.html?AWSAccessKeyId=leNM%2FocHLQ%2ByqCuwtsgoza8buGoeRSlHuoDGRnlb&AssociateTag=ajaykumar9207-21&ASIN.1=B07CQ6Q52H&Quantity.1=1&ASIN.2=B07CQ6Q52H&Quantity.2=1&ASIN.3=B07CQ6Q52H&Quantity.3=1&ASIN.4=B07CQ6Q52H&Quantity.4=1&ASIN.5=B07CQ6Q52H&Quantity.5=1