I am going to break this into two sections. Firstly, a bare minimum requirement. Secondly, an “ideal”, more complicated requirement.
First
Upon a new entry being put into a table of mine (“Favourites”) via a mobile app POSTing data, i’d like backendless to do a simple HTTP Post request to https://exp.host/--/api/v2/push/send with a body like:
[
{
"to": "ExponentPushToken[zzjgmSH_RfMFuj2RiiwY_B]",
"title": "Test Title",
"body": "[User's name] has favourited an article"
}.
{
"to": "ExponentPushToken[zzjgmSH_RfMFuj2RiiwY_E]",
"title": "Test Title",
"body": "[User's name] has favourited an article"
},
{
"to": "ExponentPushToken[zzjgmSH_RfMFuj2RiiwY_H]",
"title": "Test Title",
"body": "[User's name] has favourited an article"
}
]
The tokens are stored in a field in the users table. I need backendless to select user tokens where the users have a matching code in the “organisationCode” field compared to the user that is POSTing data.
So far i have added this in my backend event handler area
Can someone now advise on the JS code i’d need to send a push notification simply saying:
“[User’s name] has favourited an article” ?
Second
Ideally upon a new favourite being put in to the system i actually need backendless to:
Populate a “notifictions” table with this body:
{
“attach” : “[potential link to an image goes here]”,
“description” : “just favourited an article”,
“organisationCode” : “e8xqdl”,
“type” : “like”,
“userName” : “John Smith”,
“ownerId” : “94A40363-4F7E-F774-FF87-B64760001A00”
}
Once the above is POSTed ^ , then POST to {{backendlessAPIurl}}/{{Application ID}}/{{REST API Key}}/data/{{Table Name}}/{{Data Object ID}}/{{Data Relation Name}}
with
{"userLink" : "[user_ objectId]" }
where user_objectId is the backendless object ID for that user
This is to add a link to the users table for every entry in the notifications table.
Push to the URL as mentioned in the “First” section of this post to trigger push notifications
I am using expo push service because its far easier than using the backendless one for expo react native projects - which requires detaching from expo etc.
Can you also advise me on how i retrieve data from other tables ?
Unfortunately, you can’t specify field of relation items, but you can handle that with BusinessLogic, just remove fields what you don’t want to send to the client in your ApiService or EventHandler
If i want to send a message body of “John Smith has favourited an article” to https://exp.host/--/api/v2/push/send
Then on the table in question when a notification entry gets created i am going to ultimately need to get description, userLink.deviceToken and userLink.name to generate that message and send the right token to https://exp.host/--/api/v2/push/send .
It generally sounds like i just can’t do that, so i am going to have to get the client to do all the logic
no, I mean you can’t load specific fields of related object, for example
you have class Address with the next field { city, code } and class User { name, email, address:Address }
and you try to load the user object, you can filter fields only of the top object through setProperties(‘name’) method, but for relations it won’t work
and as I understand now you just want to load some parent object with child object in a single api call, and then use property of related object, for loading relations you should use setRelated(‘userLink’) method
sorry, but I’m not sure that I understand your question, I can see that you already able to retrieve the object with “userLink” relation and there are properties “name” and “deviceToken”, and you can use it
if you are looking for a way to get only these two fields “name” and “deviceToken” of “userLink” from the server, as I said before it’s not impossible, props filtering is applied only for the top object, not for sub-objects (relations)