Firestore queries: Invalid Payload Received - json

What am I trying to do?
Query the field named price in documents inside the collection named product_page and return the document where price==100
What did I do?
URL:https://firestore.googleapis.com/v1/projects//databases/(default)/documents/product_page/
METHOD: POST
Request Body:
{
"structuredQuery": {
"from": [
{
"collectionId": "product_page",
"allDescendants": true
}
],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "price"
},
"op": "EQUAL",
"value": {
"stringValue": "100"
}
}
}
What error do I get?
code": 400,
"message": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field."
}

You use the wrong endpoint (or method).
With the following URL and a POST method
https://firestore.googleapis.com/v1/projects/.../databases/(default)/documents/product_page
you actually call the createDocument method.
You need to use the runQuery method, which allows passing a structuredQuery object.

Related

Json Extractor in JMeter

I am using JSON extractor in JMeter. Below is my Response Body. I am using the Json path expression to capture the value, which is working fine.
Apart from the above condition, I need to add one more condition.
If the "travelID" length is equal to 33, then only I need to get the BoundID.
Example : AAA-AB1234-AAABBB-2022-11-10-1111
Total length or count of the above travelID is 33, but sometime I used to get 31,32 also but I need to capture the Bound ID only when the length is 33. Is that feasible ? Please help on the same
PFB sample response body.
{
"data": {
"RenewalDetails": [
{
"ExpiryDetails": {
"duration": "xxxxx",
"destination": "XXX",
"from": "XXX",
"value": 2,
"segments": [
{
"valudeid": "xxx-xx6262-xxxyyy-1111-11-11-1111"
}
]
},
"Itemdetails": [
{
"BoundId": "xxx-1-xxx1-111111111111-1",
"isexpired": true,
"FamilyCode": "PREMIUM",
"availabilityDetails": [
{
"travelID": "AAA-AB1234-AAABBB-2022-11-10-1111",
"quota": "X",
"scale": "XXX",
"class": "X"
}
]
}
]
}
]
},
"warnings": [
{
"code": "xxxx",
"detail": "xxxxxxxx",
"title": "xxxxxxxx"
}
]
}
I don't think it's possible with JSON Extractor, I would rather suggest going for JSR223 PostProcessor and the following Groovy code:
def BoundId = new groovy.json.JsonSlurper().parse(prev.getResponseData())
.data.RenewalDetails[0].Itemdetails.find { itemDetail ->
itemDetail.availabilityDetails[0].travelID.length() == 33
}?.BoundId
vars.put('BoundId', BoundId ?: 'Not Found')
You will be able to refer extracted value as ${BoundId} later on where required.

Can't access property from JSON file, why?

Here's the JSON:
data = {
"company_name": "חברה לדוגמה",
"audit_period_begin": "01/01/2021",
"audit_period_end": "31/12/2021",
"reports": [
{
"type": {
"he": "מאזן",
"en": "Balance Sheets"
},
"fin_statement": "BS",
"sections": [
{
"section_name": {
"he": "נכסים שוטפים",
"en": "Current Assets"
},
"totals": {
"2020": {
"final_total_local": 100000,
"final_total_foreign": 0
},
"2021": {
"final_total_local": 110000,
"final_total_foreign": 0
}
},
"subsections": [
{......(the rest is irrelevant)
and I'm trying to call:
data.reports[0].sections[0]['totals']
but I get an error:
Element implicitly has an 'any' type because expression of type '"totals"' can't be used to index type
and can't read the property, why?
After you acquire data.reports[0].sections[0].totals probably successfully you are accessing it as if it was an array, whereas it's an object. try data.reports[0].sections[0]['totals']["2020"] instead of data.reports[0].sections[0]['totals'][2020]. This is just a guess as you didn't provide enough code.

Autodesk Forge API - Patch Item Input Error

I am trying to use the PATCH projects/:project_id/items/:item_id endpoint in order to update the "displayName" attribute of an item in BIM360. There is an example on how to do exactly that in the Forge documentation, but for some reason I am getting an 400 error.
Here is my payload:
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "items",
"id": "ITEM_URN",
"attributes": {
"displayName": "NEW_ITEM_NAME.EXTENSION"
}
}
}
Here is the error I get:
{
"jsonapi": {
"version": "1.0"
},
"errors": [
{
"id": "a4c43bbb-9e34-4973-9f9c-58a7e1d7bdb6",
"status": "400",
"code": "BAD_INPUT",
"title": "One or more input values in the request were bad",
"detail": "Request input is invalid for this operation."
}
]
}
I successfully use the same endpoint in order to change the parent folder for this same item (as described in this post answer: Autodesk Forge; Pragmatically changing file location without new upload ), so the problem must be in the update "displayName" portion. Here the successful payload sample that returns a 200 answer:
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "items",
"id": "ITEM_URN",
"relationships": {
"parent": {
"data": {
"type": "folders",
"id": "DESTINATION_FOLDER_URN"
}
}
}
}
}
Forge Documentation with example: https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-items-item_id-PATCH/
What am I missing in order to update the "displayName" attribute?
If you want to change the file name, you can change tip version name and title , creating new version is required, but you don't have to upload file again. Please try the API at https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-POST/ :
POST /versions?copyFrom={tip_version_urn}
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "versions",
"attributes": {
"name": "newName"
}
}
}
A new tip version will be created with the updated name.

Outlook Event API : At least one property failed validation error

I'm creating an Outlook event via Outlook API by providing following JSON input :
{
"subject":"bla bla bla",
"start":{
"dateTime":"2018-01-14T17:00:00",
"timeZone":"India Standard Time"
},
"Attendees": [
{
"EmailAddress": {
"Address": "janets#a830edad9050849NDA1.onmicrosoft.com",
"Name": "Janet Schorr"
},
"Type": "Required"
}
]
}
However I'm getting the following error response :
{
"error": {
"code": "ErrorPropertyValidationFailure",
"message": "At least one property failed validation.",
"innerError": {
"request-id": "6f3d1676-77cc-49b0-87a2-b96b6ed1f15d",
"date": "2018-01-12T05:25:10"
}
}
}
If I pass the end attribute in the above JSON, the event is created successfully. The below JSON works fine :
{
"subject":"bla bla bla",
"start":{
"dateTime":"2018-01-14T17:00:00",
"timeZone":"India Standard Time"
},
"end":{
"dateTime":"2018-01-14T17:00:00",
"timeZone":"India Standard Time"
},
"Attendees": [
{
"EmailAddress": {
"Address": "janets#a830edad9050849NDA1.onmicrosoft.com",
"Name": "Janet Schorr"
},
"Type": "Required"
}
]
}
Is it required to pass an end attribute for event creation? Or is there something wrong with the above JSON input?
Yes, end is required. Outlook/Exchange don't support events with no end date :)

Use Apps Script URLFetchApp to access Google Datastore Data

I want to experiment with Google Datastore via Apps Script because I have a current solution based on Google sheets that runs into timeout issues inherent in constantly transacting with Drive files. I've created a test project in Google cloud with a service account and enabled library MZx5DzNPsYjVyZaR67xXJQai_d-phDA33
(cGoa) to handle the Oauth2 work. I followed the guide to start it up here and got all the pertinent confirmation that it works with my token (and that removing the token throws an 'authentication failed prompt').
Now I want to start with a basic query to display the one entity I already put in. I can use the API Explorer here and run this query body:
{
"query": {}
}
and get this result:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707333336492774"
},
"path": [
{
"kind": "Transaction",
"id": "5629499534213120"
}
]
},
"properties": {
"CommentIn": {
"stringValue": "My First Test Transaction"
},
"Status": {
"stringValue": "Closed"
},
"auditStatus": {
"stringValue": "Logged"
},
"User": {
"stringValue": "John Doe"
},
"Start": {
"timestampValue": "2017-08-17T18:07:04.681Z"
},
"CommentOut": {
"stringValue": "Done for today!"
},
"End": {
"timestampValue": "2017-08-17T20:07:38.058Z"
},
"Period": {
"stringValue": "08/16/2017-08/31/2017"
}
}
},
"cursor": "CkISPGogc35whh9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyGAsSC1RyYW5zYWN0aW9uGICAgICAgIAKDBgAIAA=",
"version": "1503004124243000"
}
],
"endCursor": "CkISPGogc35wcm9qZWN0LWlkLTUyMDAxxDcwODA1MDY0OTI3NzRyGAsSC1RyYW5zYWN0aW9uGICAgICAgIAKDBgAIAA=",
"moreResults": "NO_MORE_RESULTS"
}
}
I try to do the same thing with this code:
function doGet(e)
{
var goa = cGoa.GoaApp.createGoa('Oauth2-Service-Account',
PropertiesService.getScriptProperties()).execute(e);
if(goa.hasToken()) {var token = goa.getToken();}
var payload = {"query":{}}
;
var result = UrlFetchApp.fetch('https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runQuery',
{
method: "POST",
headers: {authorization: "Bearer " + goa.getToken()},
muteHttpExceptions : true,
payload: payload
});
Logger.log(result.getBlob().getDataAsString());
}
and get this error in the logger:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"query\": Cannot bind query parameter. 'query' is a message type. Parameters can only be bound to primitive types.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"query\": Cannot bind query parameter. 'query' is a message type. Parameters can only be bound to primitive types."
}
]
}
]
}
}
If I try to use another word such as 'resource' or 'GqlQuery', I get this error:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"GqlQuery\": Cannot bind query parameter. Field 'GqlQuery' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"GqlQuery\": Cannot bind query parameter. Field 'GqlQuery' could not be found in request message."
}
]
}
]
}
}
I can't tell from the API Documentation what my syntax is supposed to be. Can anyone tell me how to compile a functional request body from Apps Script to Datastore?
You need to set the contentType of your payload as well as stringify your JSON payload as follows:
var result = UrlFetchApp.fetch(
'https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runQuery',
{
'method':'post',
'contentType':'application/json',
'headers': {authorization: "Bearer " + goa.getToken()},
'payload':JSON.stringify(payload)
}
);