How to work with Firebase cloud messaging OR conditions? - firebase

I have 2 instance IDs registered. 1st one is subscribed to topic dogs and 2nd one is subscribed to topic cats.
I have tried to use the given example https://firebase.google.com/docs/cloud-messaging/js/topic-messaging#build_send_requests
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d ' {
"notification": {
"title": "FCM Message",
"body": "This is a Firebase Cloud Messaging Topic Message!",
},
"condition": "'dogs' in topics || 'cats' in topics"
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
After I ran this cURL I didn't got any errors nor did I got any notifications
{
"name": "projects/myproject-b5ae1/messages/7533715453624815804"
}
If I send notification to exact topic or exact instance id it works, but not with OR condition.
Is here some rules that does not allow to use only OR without AND or is here something else I missed?

Related

Error 2003 when analyzing results for Custom Model

Using this link: https://learn.microsoft.com/en-us/azure/cognitive-services/form-recognizer/quickstarts/curl-train-extract I follow each step and use the sample data in the guide. All of them are successful until the last step which is "Get the Analyze results", where it returns the following:
{
"status": "failed",
"createdDateTime": "2020-07-09T14:59:12Z",
"lastUpdatedDateTime": "2020-07-09T14:59:14Z",
"analyzeResult": {
"version": null,
"readResults": null,
"pageResults": null,
"documentResults": null,
"errors": [
{
"code": "2003",
"message": "Download failed. Please check your input URL."
}
]
}
}
Unfortunately, there are no references to error codes and possible explanation/solutions. Assistance is highly appreciated.
The error message is quite clear: the url that you provided for the analysis does not allow the service to download the document.
Please check the content that you sent during the operation called "Analyze forms for key-value pairs and tables":
curl -v "https://<Endpoint>/formrecognizer/v2.0/custom/models/<model ID>/analyze" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: <subscription key>" -d "{ \"source\": \""<SAS URL>"\" } "
In particular, can you detail the last part? The piece with the '' block is the one causing the error

issues while posting data from curl to Firestore throw curl

I am very beginner to Google Firestore (also to Firebase). I am doing a simple POC and I am suffering a bit to interact with FireStore. Well, reading the data from Angular worked as a charm so easy. Nevertheless, simple actions like add a new data from curl or deleting the collection from FireBase Cli has taken me the whole day without progress . Just to stress how dummy I am in FireStore, I have used ElasticSearch local installed so I am trying similar behaviours/tools/functionalities like posting/creating fields from curl/postman (it is not part of this question compare one another, just exposing my limitations) but I just can't move forward.
This is how I connected successfully from Angular:
firebaseConfig : {
apiKey: "*** removed ***",
authDomain: "transfer-status-realtime.firebaseapp.com",
databaseURL: "https://transfer-status-realtime.firebaseio.com",
projectId: "transfer-status-realtime",
storageBucket: "transfer-status-realtime.appspot.com",
messagingSenderId: "143612370857",
appId: "1:143612370857:web:a9d0b21e3a58520ed02eb8",
measurementId: "G-WT5C346D7T"
}
I have based mainly my tentatives in Making Rest Calls and other stack overflow question
My last and recent tried:
c:\temp>curl -X POST -H "Content-Type: application/json" -d'{"fields": {"status": "success"}}' "https://firestore.googleapis.com/v1beta1/projects/transfer-status-realtime/databases/(default)/documents/transfers?&key=***removed***"
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 8
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Closing quote expected in string.\n\n^",
"status": "INVALID_ARGUMENT"
}
}
So my main issue: how add data to FireStore from curl?
In case it matter, here is my database console:
Other tentatives probably in wrong direction I have tried are:
According to https://firebase.google.com/docs/database/rest/save-data, I can save fields by using PUT so I tried write a curl command and I got stuck because I don't know what would be the "fireblog" in my case?
curl -X PUT -d '{
"transfers": {
"id": "idfromPut",
"status": 1
}
}' 'https://transfer-status-realtime.firebaseio.com/rest/saving-data/fireblog/users.json'
I also tried but what would be message_list in my case?
curl -X POST -d '{"status" : 2}' 'https://transfer-status-realtime.firebaseio.com/message_list.json'
*** edited
c:\temp>curl -X POST -H "Content-Type: application/json" -d "{\"fields\": {\"status\": \"success\"}}" "https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers?&key=*** removed ***"
{
"error": {
"code": 400,
"message": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.fields[0].value",
"description": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\""
}
]
}
]
}
}
In case it is relevant, same issue using external json file
C:\WSs\reactive-stack\reactive-front\src>curl -X POST -H "Content-Type: application/json" -d #load-data-tofirestore.json "https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers?&key=***removed"
{
"error": {
"code": 400,
"message": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.fields[0].value",
"description": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\""
}
]
}
]
}
}
And here is the json file
{"fields": {"status": "success"}}
* SOLUTION *
from cUrl
C:\WSs\reactive-stack\reactive-front\src>curl -H "Content-Type: application/json" -X POST https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers -d "{\"fields\": { \"status\": { \"stringValue\": \"outro status\" } }}"
{
"name": "projects/transfer-status-realtime/databases/(default)/documents/transfers/ddwHxjy7eQV3640pW0Xx",
"fields": {
"status": {
"stringValue": "outro status"
}
},
"createTime": "2020-04-06T16:21:16.453553Z",
"updateTime": "2020-04-06T16:21:16.453553Z"
}
from PowerShell
PS C:\Users> $body = #"
>> {
>> "fields": {
>> "status": {
>> "stringValue": "fracasso"
>> }
>> }
>> }
>> "#
>>
PS C:\Users\Cast> $params = #{
>> Uri = 'https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers'
>> Method = 'POST'
>> Body = $body
>> ContentType = 'application/json'
>> }
>>
PS C:\Users\Cast> Invoke-RestMethod #params
name fields createTime
---- ------ ----------
projects/transfer-status-realtime/databases/(default)/documents/transfers/z4TB6gzcgXMRUGR8ecek #{status=} 2020-04-06...
PS C:\Users>
I believe the root cause of your issue is due to cURL on a windows system. As seen in this other question, there are limitations on how the command line arguments are parsed in a windows shell.
Instead of using this:
-d'{"fields": {"status": "success"}}'
You should state your payload as:
-d "{\"fields\": {\"status\": \"success\"}}"
Another solution could be writing the JSON in a file and using its path in the cURL query. I believe you could keep the right JSON format this way, but you would be forced to use a file, which is far from optimal if you don't intend to send the same payload multiple times:
-d #file_with_data.json

Firebase Messaging : Successful but not delivered

I created a Device Group in firebase Messaging - Documentation here and got back the notification_key
Now when I use that notification_key to send messages using Firebase Console, they are sent and delivered to all registered devices.
But doing the same thing outside the console (for example in postman) does not work, I do however get a success message for all devices and zero failures but the devices never receive the message.
Response in Postman
{
"success": 7,
"failure": 0
}
My post request is the following
curl -X POST \
https://fcm.googleapis.com/fcm/send \
-H 'Authorization: key=***' \
-H 'Content-Type: application/json' \
-d '{
"to": "my_notification_key",
"data": {
"hello": "test !"
}
}'
I feel like I am missing something but as per provided documentation that all it should need to send a message
From Firebase Documentation
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "aUniqueKey",
"data": {
"hello": "This is a Firebase Cloud Messaging Device Group Message!",
}
}
any idea what is going wrong here as I receive success message but the message is never delivered to the devices?
I had to pass the notification instead of just 'data' as following
"to" : "notification_key",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
}
Hope this helps someone.

LinkedIn API request fails with "Unpermitted fields present in RESOURCE_KEY: Data Processing Exception while processing fields [/memberId]"

I'm trying the following request:
GET https://api.linkedin.com/v2/people/(id:urn:li:person:<person id>)?oauth2_access_token=<token>&projection=(results*(localizedFirstName,vanityName))
But I always get a:
{
"serviceErrorCode": 100,
"message": "Unpermitted fields present in RESOURCE_KEY: Data Processing Exception while processing fields [/memberId]",
"status": 403
}
If I try to do it using the alternative API:
GET https://api.linkedin.com/v2/people?ids=List((id:urn:li:person:<person id>))&oauth2_access_token=<token>&projection=(results*(localizedFirstName,vanityName))
An Internal Server Error is returned:
{
"message": "Internal Server Error",
"status": 500
}
I'm using Google Chrome to perform those requests.
I tried using Postman too.
Headers:
X-Restli-Protocol-Version: 2.0.0
Authorization: Bearer <token>
Got:
{
"serviceErrorCode": 0,
"message": "Syntax exception in path variables",
"status": 400
}
My app permissions are:
r_emailaddress
r_ads
w_organization_social
rw_ads
r_basicprofile
r_liteprofile
r_ads_reporting
r_organization_social
rw_organization_admin
w_member_social
I tried other APIs (socialActivity, ugcPosts) and everything looks fine.
I checked my API usages at https://www.linkedin.com/developers/apps/<id>/usage and people usage is currently 0%.
The tested user profiles are also public.
You should only use the id (instead of the urn). also the fields projection is wrong:
Use:
projection=(localizedFirstName,vanityName)
Instead of:
projection=(results*(localizedFirstName,vanityName))
As example:
curl -H "X-Restli-Protocol-Version: 2.0.0" \
"https://api.linkedin.com/v2/me?oauth2_access_token=<TOKEN>&projection=(id)"
Will return
{
"id": <ID>
}
and use it as:
curl -H "X-Restli-Protocol-Version: 2.0.0" \
"https://api.linkedin.com/v2/people/(id:<ID>)?oauth2_access_token=<TOKEN>&projection=(localizedFirstName,vanityName)"
So:
{
"vanityName": "<VANITY-NAME>",
"localizedFirstName": "<NAME>"
}
Hope this help
id parameter needs only person_id but you are providing urn.Try this https://api.linkedin.com/v2/people/(id:person_id) and don't forgot to include X-RestLi-Protocol-Version:2.0.0 in header while making call.

Ad Targeting - Find Entities by URNs API ClassCastException error message

I have some problem with the "Find Entities by URNs" API in order to retrieve the metadata and value information for a collection of URNs.
If I use the URL described in the doc (Sample request) with a valid access token:
https://api.linkedin.com/v2/adTargetingEntities?q=urns&urns=List(urn%3Ali%3AfieldOfStudy%3A100990,urn%3Ali%3Aorganization%3A1035,urn%3Ali%3Aseniority%3A9)&locale=(language:en,country:US)&oauth2_access_token=<a-valid-token>
I receive the message:
{
"serviceErrorCode": 0,
"message": "java.lang.ClassCastException",
"status": 500
}
Anyone have experience the same issue? Any idea how to fix it?
Also: how can i contact for technical support as in this case?
UPDATE:
I made some try and I fix using the following version:
https://api.linkedin.com/v2/adTargetingEntities?q=urns&urns=urn%3Ali%3AfieldOfStudy%3A100990&urns=urn%3Ali%3Aorganization%3A1035&urns=urn%3Ali%3Aseniority%3A9&locale.language=it&locale.country=IT&oauth2_access_token=<a-valid-token>
BUT the locale/language translation is not working. Could be this a working solutions?
From the support team:
Our docs are missing 1 critical piece of information. Whenever using
LIST and encoded URNs in the URL, we expect an additional header 'x-restli-protocol-version: 2.0.0'
The correct API call would be Request:
curl -X GET \
'https://api.linkedin.com/v2/adTargetingEntities?q=urns&urns=List(urn%3Ali%3Aindustry%3A1,urn%3Ali%3Aseniority%3A9)&locale=(language:it,country:IT)'
\
-H 'x-restli-protocol-version: 2.0.0' \
-H 'Authorization: Bearer <Token>'
Response:
{
"elements": [
{
"facetUrn": "urn:li:adTargetingFacet:industries",
"name": "Difesa e spazio",
"urn": "urn:li:industry:1"
},
{
"facetUrn": "urn:li:adTargetingFacet:seniorities",
"name": "Partner",
"urn": "urn:li:seniority:9"
}
],
"paging": {
"count": 2147483647,
"links": [],
"start": 0
}
}
Yes, it does provide a response in locale.
Hope this can help other guys in the future

Resources