Firestore Update a document field Using Rest API - firebase

Im trying to perform PATCH Opeartion in cloud firestore using REST API.
This is my Request body
`{
"fields": {
"name": {
"stringValue":"Dinesh"
}
}
}`
When i fire the request , All the existing fields inside the document are getting deleted and only the name field is getting updated. In the Documentation they have given the Document Mask. but i dont understand how it works , neither im able to find any samples for that. Somebody know how to update only one field inside the document without affecting other fields ?

Without a DocumentMask object, the patch method defaults to replacing the Firestore Document with the request body rather than updating the submitted fields and retaining omitted fields.
The DocumentMask is submitted as an updateMask parameter containing the fieldPaths to be patched. It took a while but thanks to this answer and a lot of attempts I figured out that each fieldPath property of the updateMask object needs to be individually included in the query string of the request url:
https://firestore.googleapis.com/v1beta1/projects/{projectId}/databases/{databaseId}/documents/{document_path}?updateMask.fieldPaths=status&updateMask.fieldPaths=title
Where status and title are two fields in the request body. Note that fields included in the request body are disregarded if they are omitted from the query string, remaining unchanged.

Here is another example giving this json structure from firestore
"fields": {
"eth0": {
"mapValue": {
"fields": {
"address": {
"stringValue": "172.0.0.1"
},
"port": {
"stringValue": "8080"
},
"endpoint": {
"stringValue": "10.0.5.24"
}
}
}
}
}
Then to update the endpoint field only
curl -sSLX PATCH \
-H "Authorization: Bearer {TOKEN}" \
-H "Content-type: application/json" \
-d "{
\"fields\": {
\"eth0\": {
\"mapValue\": {
\"fields\": {
\"endpoint\": {
\"stringValue\": \"10.10.2.24\"
}
}
}
}
}
}" \
"https://firestore.googleapis.com/v1/projects/{project-id}/databases/(default)/documents/{collection}/{document}?updateMask.fieldPaths=eth0.endpoint")

Your request body is ok. But you need to use the update mask.
From reading the documents I found that the DocumentMask is used to restrict a get or update operation on a document to a subset of its fields. So by adding 'name' to your field paths on the mask, it will only allow you to update that specific field and the others won't get deleted.
You can read more about it here.

Related

Exist some way to pass custom parameter to short dynamic link on Firebase?

I know how to pass a custom parameter from a DynamicLink created in FireBase and get it on my app but the problem is that I can only make this work with the large link version, like this:
https://example.page.link/?link=https://example.com.br/?PARAMETER=VALUE&apn=com.example.br
The problem is that the link is too large, how can I send CUSTOM parameter with the short version from DynamicLink on Firebase?
You can probably get it to work if you send a request body instead of URL parameters. The REST docs explain how to:
{
"dynamicLinkInfo": {
"domainUriPrefix": string,
"link": string,
},
"suffix": {
"option": "SHORT" or "UNGUESSABLE"
}
}

Follow Azure acklog item via HTTP Request

Is there a way to follow an Azure Backlog item or to add it into the list of the items I'm following via HTTP Request?
Here is the way I get all work items I'm following:
POST https://dev.azure.com/companyName/projectName/_apis/wit/wiql?api-version=5.1&Authorization=Basic BASE64PATSTRING
Body:
{
"query": "Select [System.Id], [System.WorkItemType] From WorkItems Where [System.Id] IN(#Follows)"
}
Thanks in advance for your help.
We can follow the work item via REST API, a skeleton version looks like this:
API:
POST https://dev.azure.com/{org name} /_apis/notification/Subscriptions?api-version=5.1
Request body
{
"filter": {
"type": "Artifact",
"artifactType": "WorkItem",
"artifactId": "70"
}
}
Note: artifactId is work item ID
Result:

Insert a Map in DynamoDB

I'm trying to insert map data into a DynamoDB table using API Gateway. Here's my payload:
{
"TableName":"OrderDB",
"Item":{
"_id": {"S":"04FA887FP2S5R"},
"_rev": {"S":"9-12e098e2490e1b7c9782597226689403"},
"_merchantId":{"S":"AXN3EKXT0SJ61"},
"doc":{"M":{"something":"storedHere"} }
}
And my body mapping template in API Gateway:
{
"TableName": "$input.path('$.TableName')",
"Item": $input.json('$.Item')
}
Everything works as expected if I remove the doc item from the payload. With trying to post with the map I get the following error:
{
"__type": "com.amazon.coral.service#SerializationException",
"Message": "Unexpected value type in payload"
}
All of the examples that I see suggest using the DynamoDB document mapping object, but I don't think this is possible for me because I'm using API Gateway to connect directly to DynamoDB. Is it possible to insert a map this way?
Your map entry needs the same format as the rest of the items, so instead of "doc":{"M":{"something":"storedHere"} } it should be "doc":{"M":{"something":"S": "storedHere"} }

Google Admin SDK - Users: Patch - Issue using Strings

i have an issue using the Users: Patch - API.
I try to patch the name of the primary organization of a user using the following Request Body:
{
"organizations":[
{
"name":"Org. Name",
"primary":true,
"type":work
}
]
}
The values of the users entry get patched, but the result looks like:
{
"organizations":[
{
"name": "\"Org. Name\"",
"primary": true,
"type": "work"
}
]
}
The problem: the VCard entry of the user shows "Org. Name" instead of Org. Name as it should.
Is it possible to prevent the string getting formatted as a string again by the API?
Thank you for your help!
Lukas

How to delete particular value from JSON in user preference of Alfresco

When I use the following link
http://localhost:8080/alfresco/service/api/people/admin/preferences?pf=org.my
it returns a json structure like this
{"org":
{"ivory":
{"share":
{"site":
{"search":
{"dashlet":
{"component-1-1":
{"search-definition":
{"fromdate": "01\/02\/2015",
"author": "jhone",
"todate": "30\/04\/2015",
"term": "pensions"
}
}
}
}
}
}
}
}
}
How can I delete author section from this JSON?
The preferences REST API has a delete webscript. To delete an item from the preferences store, make sure the filter specified in the pf parameter identifies just the item you want to delete and then call it with a HTTP delete method.
E.g. a HTTP GET to this URL:
http://localhost:8080/alfresco/service/api/people/admin/preferences?pf=org.alfresco.share.sites.favourites.12345
will return true if that site is favourited. To remove it from the favourites, make a HTTP DELETE request for the same URL.

Resources