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
Related
I would like to retrieve UGC posts from organization's profile using the ugcPosts API. I would also like to receive links to video streams with the response, so I use the following projection (based on this answer):
(paging,elements*(id,created,specificContent(com.linkedin.ugc.ShareContent(shareMediaCategory,shareCommentary,media(*(media~:playableStreams,originalUrl,description,title,thumbnails))))))
My whole request looks like this (retrieving the posts of the official test organization):
curl --request GET \
--url 'https://api.linkedin.com/v2/ugcPosts?q=authors&sortBy=LAST_MODIFIED&projection=(paging%2Celements*(id%2Ccreated%2ClastModified%2Cauthor%2CspecificContent(com.linkedin.ugc.ShareContent(shareMediaCategory%2CshareCommentary%2Cmedia(*(media~%3AplayableStreams%2CoriginalUrl%2Cdescription%2Ctitle%2Cthumbnails))))))&authors=List(urn%3Ali%3Aorganization%3A2414183)' \
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
--header 'X-Restli-Protocol-Version: 2.0.0'
The request works as fine. But I run into an issue if I want to follow to the next page using the provided URL in paging; this is the relevant response:
{
"paging": {
"total": 284243,
"count": 10,
"start": 0,
"links": [
{
"rel": "next",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=10&count=10&sortBy=LAST_MODIFIED&projection=%28paging%2Celements*%28id%2Ccreated%2ClastModified%2Cauthor%2CspecificContent%28com.linkedin.ugc.ShareContent%28shareMediaCategory%2CshareCommentary%2Cmedia%28*%28media~%3AplayableStreams%2CoriginalUrl%2Cdescription%2Ctitle%2Cthumbnails%29%29%29%29%29%29&authors=List(urn%3Ali%3Aorganization%3A2414183)"
}
]
}
}
On the first page, you can see that parentheses in the projection parameter got URL encoded, while authors parameter remains the same. This request still works, but if I follow the URL one more time, I recieve the following paging data:
{
"paging": {
"total": 284243,
"count": 10,
"start": 10,
"links": [
{
"rel": "prev",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=0&count=10&sortBy=LAST_MODIFIED&projection=%2528paging%252Celements*%2528id%252Ccreated%252ClastModified%252Cauthor%252CspecificContent%2528com.linkedin.ugc.ShareContent%2528shareMediaCategory%252CshareCommentary%252Cmedia%2528*%2528media~%253AplayableStreams%252CoriginalUrl%252Cdescription%252Ctitle%252Cthumbnails%2529%2529%2529%2529%2529%2529&authors=List(urn%3Ali%3Aorganization%3A2414183)"
},
{
"rel": "next",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=20&count=10&sortBy=LAST_MODIFIED&projection=%2528paging%252Celements*%2528id%252Ccreated%252ClastModified%252Cauthor%252CspecificContent%2528com.linkedin.ugc.ShareContent%2528shareMediaCategory%252CshareCommentary%252Cmedia%2528*%2528media~%253AplayableStreams%252CoriginalUrl%252Cdescription%252Ctitle%252Cthumbnails%2529%2529%2529%2529%2529%2529&authors=List(urn%3Ali%3Aorganization%3A2414183)"
}
]
}
}
You can see here that the projection parameter got URL-encoded again (having %252C for parens) and following that URL returns error 400.
I think this is a bug in the API, but since LinkedIn recommends to use Stack Overflow for support, I just wrote this up here, hopeful someone notices. Perhaps could you suggest another way of contacting LinkedIn about this bug in their API?
Meanwhile I resorted to constructing the pagination URL manually.
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
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.
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
Trying to add branch restriction to a repository, I was successful in adding a rule, however, I cannot get a group added to the rule.
curl -XPOST --user user:password -H "Content-Type: application/json" -d '{"kind": "push", "pattern": "testing*", "groups": {"name": "testleads"}}' $URL/api/2.0/repositories/team/repo/branch-restrictions
Result:
{"error": {"message": "malformed groups"}}
I have tried different combinations in the groups using full_slug, slug and also changing the inheritance types.
-d '{"kind": "push", "pattern": "testing*", "groups":["name": "devleads"]}'
-d '{"kind": "push", "pattern": "testing*", "groups": {"name": "devleads"}}'
Has anyone tried this?
After a lot of tries, I narrowed it down to this JSON input to be able to add branch restrictions
-d '{"kind": "push", "pattern": "test*", "value": null, "groups": [{"name": "devLeads", "account_privilege": null, "full_slug": "team-name:devleads", "owner": {"username": "team-name", "display_name": "Team Name ", "type": "team"}, "type": "group", "slug": "devleads"}]}'
I'm late to the game but figured my answer might be useful for anyone who is struggling with this like I was just now. I found the minimum syntax for a group specification is as follows:
'groups': [{'name': 'development_team'}]
So, in my context (using python) the following could be posted to the BitBucket API successfully:
request_json = {
"kind": "push",
"branch_match_kind": "glob",
"pattern": "*_bugfix",
'groups': [{'name': 'development_team'}]
}
lock_response = requests.post(api_url, json=request_json, auth=bb_creds)