Creating embedded entities with the datastore command line tool - google-cloud-datastore

I'm trying to use the Google cloud datastore command line interface to create arrays of embedded entities. I've figured out how to create an embedded entity value as follows:
{
"properties": {
"age": {
"integerValue": "5"
},
"height": {
"integerValue": "6"
}
}
}
and how to create an array value as follows:
{
"values": [
{
"stringValue": "one"
},
{
"stringValue": "two"
}
]
}
But I haven't figured out how to add an embedded value to an array. For example:
{
"values": [
{
"stringValue": "one"
},
{
"stringValue": "two"
},
{
"embeddedEntityValue": {
"properties": {
"age": {
"integerValue": "5"
},
"height": {
"integerValue": "6"
}
}
}
}
]
}
gives the error:
"One or more values in this array doesn't look right. If you include values, make sure they are Datastore array values in JSON format."

I believe embeddedEntityValue should be changed to entityValue. Below is an example that shows an Array field with two embedded entities:
{
"values": [
{
"entityValue": {
"properties": {
"areaCode": {
"stringValue": "40"
},
"countryCode": {
"stringValue": "91"
},
"subscriberNumber": {
"stringValue": "2722 5858"
}
}
}
},
{
"entityValue": {
"properties": {
"countryCode": {
"stringValue": "91"
},
"subscriberNumber": {
"stringValue": "6666 0000"
},
"areaCode": {
"stringValue": "80"
}
}
}
}
]
}

Related

BatchWrite REST API JSON Structure for FireStore

I know how to compose JSON when you want to create a single document on FireStore.
# Query String
"updateMask.fieldPaths": [
"`price`",
"`status`"
]
# Body
"fields": {
"price": {
"stringValue": "165.00"
},
"status": {
"stringValue": "active"
}
}
But when it comes to BatchWrite I cannot understand what the doc implies
https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents/batchWrite
Currently I'm doing this with Python library I deployed on cloud computing resource(pipedream) but I want to do this within Make.com and its "Make API Call" module so I need to know the curl style or REST JSON syntax.
I'm assuming fields go to "writes" but not sure what goes to "labels" object.
Exactly what's the write structure for this call?
{
"writes": [
{
"update": {
"name": "projects/project_id/databases/(default)/documents/service_order/352003090342435.5f357270173e8c70878.-9486573",
"fields": {
"managed_by": {
"booleanValue": "false"
},
"location2": {
"booleanValue": "false"
},
"made_by": {
"stringValue": "352003090342435.5eda4f3c17284c58460.90921842"
},
"phone2": {
"stringValue": "0665439307"
},
"state": {
"stringValue": "confirm"
},
"write_date": {
"stringValue": "1597664391000"
},
"made_by_name": {
"stringValue": "FaridBenabdallah"
},
"description": {
"stringValue": "e1"
},
"accepted_offer": {
"booleanValue": "false"
},
"id": {
"stringValue": "352003090342435.5f357270173e8c70878.-9486573"
},
"location1": {
"stringValue": "352003090342435.5f3572a0173e8c7c336.-8281409"
},
"date_order": {
"booleanValue": "false"
},
"order_type": {
"stringValue": "Minuiserie"
},
"phone1": {
"stringValue": "0657331995"
}
}
},
"updateMask": {
"fieldPaths": [
"managed_by",
"location2",
"made_by",
"phone2",
"state",
"write_date",
"made_by_name",
"description",
"accepted_offer",
"id",
"location1",
"date_order",
"order_type",
"phone1"
]
}
}
]
}
This another stackoverflow article helped me
If there is null you need to change the intended value type to nullValue.

How to use multiple if/then in JSON schema

I have a JSON schema defined as below -
{
"type": "object",
"properties": {
"prop1": {
"type": "string"
},
"prop2": {
"type": "string"
},
"prop3": {
"type": "string"
},
"prop4": {
"type": "string"
}
},
"anyOf": [
{
"if": {
"properties": {
"prop1": {
"const": "v1"
},
"prop2": {
"const": "v2"
}
}
},
"then": {
"required": [
"prop1",
"prop2",
"prop3"
]
}
},
{
"if": {
"properties": {
"prop1": {
"const": "v11"
},
"prop2": {
"const": "v22"
}
}
},
"then": {
"required": [
"prop1",
"prop2",
"prop4"
]
}
}
],
"required": [
"prop1",
"prop2"
]
}
A few scenarios i would like to validate -
{
"prop1": "aaa"
}
//should say prop2 is required --This works
{
"prop1": "aaa",
"prop2": "bbb"
}
//should validate to true --This works
{
"prop1": "v1"
"prop2": "v2"
}
//should say prop3 is required --This DOESN'T work
{
"prop1": "v11"
"prop2": "v22"
}
//should say prop4 is required --This DOESN'T work
Could someone please help me how to fix the above 2 test cases that doesnt work?
You need to change your anyOf to a allOf, to make sure both conditions are checked.
Due to the way you have written your if conditions, only one of them can be true at a time, so for one or the other of them (or both), the else clause will be executed, but you haven't provided an else clause, so it defaults to true, so at least one of the anyOf clauses will be true, so anyOf is true.

Firestore Pagination: how to define 'startAt'-cursor for REST?

I am trying to use a cursor and 'startAt', to paginate REST requests to Firestore. According to the Paginate-documentation, the cursor should equal to the last document of the previous query. As the REST-documentation is without an example, I tried to run it by inserting an entire document as cursor in the startAt-object; like this:
POST https://firestore.googleapis.com/v1/PROJECT-NAME/databases/(default)/documents/organizations/testManyInstructions:runQuery
{
"structuredQuery": {
"from": [
{
"collectionId": "instructions"
}
],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "belongsToDepartementID"
},
"op": "EQUAL",
"value": {
"stringValue": "toplevel-document-id"
}
}
},
"orderBy": [
{
"field": {
"fieldPath": "instructionNumber"
},
"direction": "ASCENDING"
}
],
"startAt": {
"values": [{
"document": {
"name": "projects/PROJECT-NAME/databases/(default)/documents/organizations/testManyInstructions/instructions/i0",
"fields": {
"checkbox": {
"booleanValue": false
},
"retrainTimespanDays": {
"integerValue": "365000"
},
"approvedByName": {
"stringValue": ""
},
"instructionNumber": {
"stringValue": "instr. 0"
},
"instructionCurrentRevision": {
"stringValue": "A"
},
"instructionCurrentRevisionPublishingDate": {
"timestampValue": "1999-01-01T00:00:00Z"
},
"instructionFileURL": {
"stringValue": ""
},
"instructionTitle": {
"stringValue": "dummy Title0"
},
"instructionFileUploadDate": {
"timestampValue": "1999-01-01T00:00:00Z"
},
"belongsToDepartementID": {
"stringValue": "toplevel-document-id"
},
"approvedByEmailAdress": {
"stringValue": ""
}
},
"createTime": "2022-02-18T13:55:42.807103Z",
"updateTime": "2022-02-18T13:55:42.807103Z"
}
}
]
},
"limit": 5
}
}
without the "startAt"-Object, the following code works fine and returns 5 documents.
with the "startAt"-Object, this error is returned:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"document\" at 'structured_query.start_at.values[0]': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "structured_query.start_at.values[0]",
"description": "Invalid JSON payload received. Unknown name \"document\" at 'structured_query.start_at.values[0]': Cannot find field."
}
]
}
]
}
}
]
Please advise, how to set the cursor in the startAt-object correctly.
I've run a similar query using offset instead of startAt, so I tried modifying and got it to work. This is the rest api documentation I used.
startAt requires a Cursor object which is an array of Values.
https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery
https://firebase.google.com/docs/firestore/reference/rest/v1/Cursor
https://firebase.google.com/docs/firestore/reference/rest/Shared.Types/ArrayValue#Value
I would have preferred an example as well!
"startAt": {
"values": [{
"stringValue": "Cr"
}]
},
"orderBy": [{
"field": {
"fieldPath": "Summary"
}
}],
Good luck!

SABRE Hotel Book request is missing TravelItineraryRead in the response

I'm having an issue performing the following SABRe hotel book in the CRT environment using an orchestrated workflow.
{
"CreatePassengerNameRecordRQ": {
"version": "2.3.0",
"TravelItineraryAddInfo": {
"CustomerInfo": {
"ContactNumbers": {
"ContactNumber": [
{
"NameNumber": "1.1",
"Phone": "17805555555",
"PhoneUseType": "H"
}
]
},
"Email": [
{
"Address": "chris#test.com",
"Type": "TO"
}
],
"PersonName": [
{
"NameNumber": "1.1",
"PassengerType": "ADT",
"GivenName": "Chris",
"Surname": "test"
}
]
}
},
"HotelBook": {
"BookingInfo": {
"BookingKey": "5d07cdba-0123-4510-9f9a-5257973b5f98",
"RequestorID": "SG000000"
},
"Rooms": {
"Room": [
{
"Guests": {
"Guest": [
{
...
}
]
},
"RoomIndex": 1
}
]
},
"PaymentInformation": {
"FormOfPayment": {
"PaymentCard": {
"PaymentType": "CC",
"CardCode": "VI",
"CardNumber": "4111111111111111",
"ExpiryMonth": 3,
"ExpiryYear": "2024",
"FullCardHolderName": {
"FirstName": "Chris",
"LastName": "test",
"Email": "chris#test.com"
},
"CSC": "013",
"Address": {
...
},
"Phone": {
"PhoneNumber": "17805555555"
}
}
},
"Type": "GUARANTEE"
},
"POS": {
"Source": {
"RequestorID": {
"Type": 5,
"Id": "XXX",
"IdContext": "IATA"
},
"AgencyAddress": {
"AddressLine1": "1 Lincoln Blvd",
"CountryName": {
"Code": "US"
}
},
"AgencyName": "Flying Wings",
"ISOCountryCode": "US",
"PseudoCityCode": "1MNJ"
}
}
},
"PostProcessing": {
"EndTransaction": {
"Source": {
"ReceivedFrom": "Flying Wings Web"
},
"Email": {
"Ind": true
}
}
}
}
}
The response I get is:
{
"CreatePassengerNameRecordRS": {
"ApplicationResults": {
"status": "Complete",
"Success": [
{
"timeStamp": "2021-03-08T01:18:50.544-06:00"
}
]
},
"ItineraryRef": {
"ID": "VKIJSI"
}
},
"Links": [
]
}
So a successful booking however I am expecting a TravelItineraryRead returned in the response and am not getting one. Am I missing something in the request?
Thanks.
try redisplaing the newly created reservation.
"RedisplayReservation": {
"waitInterval": 100
}
that should include the itinerary in the response

Filter Expression based on a nested object DynamoDB AppSync

I'm trying to filter out a query based on a nested object (no array). I'm currently using AppSync and DynamoDB and the expression with expression values are executed correctly. But the filtering doesn't seem to work.
This is the sample data I'm trying to get (Filter by indicator.id):
Here's my query:
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression": "pk = :pk and begins_with(sk, :sk)",
"expressionValues": {
":pk": { "S": "tenant:5fc30406-346c-42e2-8083-fda33ab6000a" },
":sk": {
"S": "school-year:2019-2020:grades:bVgA9abd:subject:m_kpc1Ae6:indicator:"
}
}
},
"filter": {
"expression": " contains(#indicatorId, :sk1) or contains(#indicatorId, :sk2) or contains(#indicatorId, :sk3)",
"expressionNames": { "#indicatorId": "indicator" },
"expressionValues": {
":sk1": {
"M": { "id": { "S": "07c658dd-999f-4e6f-95b8-c6bae422760a" } }
},
":sk2": {
"M": { "id": { "S": "0cf9f670-e284-4a93-b297-5e4a40c50228" } }
},
":sk3": { "M": { "id": { "S": "cd7902be-6512-4b47-b29d-40aff30c73e6" } } }
}
}
}
I've also tried:
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression": "pk = :pk and begins_with(sk, :sk)",
"expressionValues": {
":pk": { "S": "tenant:5fc30406-346c-42e2-8083-fda33ab6000a" },
":sk": {
"S": "school-year:2019-2020:grades:bVgA9abd:subject:m_kpc1Ae6:indicator:"
}
}
},
"filter": {
"expression": " contains(#indicatorId, :sk1) or contains(#indicatorId, :sk2) or contains(#indicatorId, :sk3)",
"expressionNames": { "#indicatorId": "indicator.id" },
"expressionValues": {
":sk1": { "S": "07c658dd-999f-4e6f-95b8-c6bae422760a" },
":sk2": { "S": "0cf9f670-e284-4a93-b297-5e4a40c50228" },
":sk3": { "S": "cd7902be-6512-4b47-b29d-40aff30c73e6" }
}
}
}
I've also tried searching around StackOverflow, and Amazon forums and haven't found it directly to my problem:
How to filter by elements in an array (or nested object) in DynamoDB
Nested Query in DynamoDB returns nothing
Referring to this answer.enter link description here
According to DDB Nested Attributes doc, the filter expression should look like the following format:
"filter" : {
"expression" : "#path.#filter = :${fp}", ## filter path parent.target = :target
"expressionNames": {
"#path" : "${path}",
"#filter" : "${fp}"
},
"expressionValues" : {
":${fp}" : $util.dynamodb.toDynamoDBJson(${$target[$fp].eq}) ## :target : value to filter for
}
}

Resources