Issues looping through graphql response in PowerShell - powershell

I am having issues looping through this data. This data is a the response from a graphql webrequest. I would like to loop through this data and execute another webrequest for each ID. I am not able to get powershell to read the nested objects.
{
"data": {
"Messages": {
"nodes": [
{
"id": "ca96b6e3-b138-46c2-92da-b13d1b2bc03c"
},
{
"id": "05035088-e681-47d1-905d-787c0967897e"
},
{
"id": "8c48af4f-326d-47e5-9714-590521cc3be8"
},
{
"id": "44cf1adc-e451-4140-9fd9-aa3a947f7e2a"
},
{
"id": "d7859528-5385-4e62-b234-a4a7978fe6a3"
},
{
"id": "b62ef4aa-29bf-4f03-9b0b-de8042b68020"
},
{
"id": "ee6e3b25-3f15-4807-9a46-3f9de4867aa5"
},
{
"id": "aed8a312-eac9-4053-abb7-bd93f07dab7a"
},
{
"id": "69421eb8-6c7a-4d80-ba24-c08ca16872c7"
},
{
"id": "9a4ffa1c-0176-420a-9257-5ebfca44b0e4"
},
{
"id": "645777ba-f29d-41c1-b750-939726712f42"
},
{
"id": "702eabb8-50dc-4808-babd-f0317a9cad94"
},
{
"id": "a8b9b755-5fbd-4ab6-8f22-6be1b4c3cc65"
},
{
"id": "e56c473f-4044-4678-9e0c-0e92f04126ad"
},
{
"id": "b3e6c14e-b7fb-451f-afc8-b7f22b1815df"
},
{
"id": "30f4f9be-32cb-4bdd-878f-fa4ff55c89fb"
},
{
"id": "08293318-5e9b-4fa0-919e-6e0611d4f89c"
},
{
"id": "5ea6b3bc-19a5-43d5-ab25-b01770676d49"
},
{
"id": "7f01e29f-6fe6-4b06-a5d5-e3e46f2f74da"
},
{
"id": "59462e10-429e-4878-9cc7-424882e016de"
},
{
"id": "20f3aaa7-a276-4339-bf37-4fe9ff9b2dcf"
},
{
"id": "65a05042-e2de-48b4-80dc-2dfff9ce4c6b"
},
{
"id": "f859f606-e3e6-4d66-8a44-e938b78c08a2"
},
{
"id": "45ce080e-83ca-4a30-84d3-e5e01f3f361a"
},
{
"id": "f8397dc3-027a-4db8-bc6a-e57c219ea836"
},
{
"id": "712cc2e6-270c-4728-a546-6bf43b072a18"
},
{
"id": "551e78cc-db91-491b-8c48-9d9ec2fc8322"
},
{
"id": "eb47d873-bfc7-4d74-ad5a-9f39a2a9cf31"
},
{
"id": "50cc9637-4384-4e47-925d-302b07bb0158"
},
{
"id": "5147ef32-c7e4-443f-97e1-53f3321616c1"
}
]
}
}
}
I tried ConvertFrom-Json but this is all that is see.
data
----
#{Messages=}

Related

Query nested object in mongodb without key

I have multiple documents saved which look like the one shown below, how would I query against a nested object without the ID to receive the right document?
Here is what I current, but this doesnt work, as I dont have the ID at the start.
db.collection.find({
"details.hardware.id": 5,
})
This is what ive tested and know works but I dont know the ID -
db.collection.find({
"100201.details.hardware.id": 5,
})
Document example -
[
{
"_id": {
"$oid": "6338b69062433c04642d26ca"
},
"100201": {
"broken": true,
"details": {
"build": {
"id": 1018458,
},
"hardware": {
"id": 5,
"model": {
"id": 131,
},
},
"id": 2811302,
"view": {
"id": 781,
}
},
"id": "100201",
"links": [
{
"details": {
"id": 7832,
},
"id": 15012,
},
{
"description": null,
"details": {
"id": 6528,
"model": {
"id": 530
}
},
"id": 15076,
}
],
"ref": false,
}
}
]
any help would be appreciated

JOLT - filtering array based on object value

how can I do this?
This is the array....
Can you please help me?
Can you please give me the answer???? Thanks a lot
{
"results": {
"data": [
{
"name": "xx",
"typeRelationship": [
{
"relationship": "parent",
"type": {
"id": "yyyyy",
}
}
],
"id": "xxxxxxxx"
},
{
"name": "yy",
"typeRelationship": [
{
"relationshipType": "parent",
"type": {
"id": "CCCC"
}
},
{
"relationshipType": "child",
"service": {
"id": "DDDD"
}
},
{
"relationshipType": "child",
"service": {
"id": "xxxxxxxx"
}
}
],
"id": "yyyyy"
}
]
}}
expected:
This is expected:
{
"data" : [ {
"id" : "xxxx",
"href" : "xxxxxx",
"relation":"parent"
} ]
}
For some reason I need to type so it does let me update!!!
This works.
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"type": {
"id": {
"xxxx": {
"#3": "data[]"
}
}
}
}
}
}
}
]
Edit 1
The below spec moves all the values which as id=xxxxx to the data array.
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"type": {
"*": {
"id": {
"xxxx": {
"#(2)": "data[]",
"#(4,relation)": "data[&3].relation"
}
}
}
}
}
}
}
}
]
This totally works.
Thanks.
Can you please let me know what is 2? 3? 4?
Because my array is a bit different and I want to fix those numbers but does not work....
{
"results": {
"data": [
{
"name": "xx",
"typeRelationship": [
{
"relationship": "parent",
"type": {
"id": "yyyyy",
}
}
],
"id": "xxxxxxxx"
},
{
"name": "yy",
"typeRelationship": [
{
"relationshipType": "parent",
"type": {
"id": "CCCC"
}
},
{
"relationshipType": "child",
"service": {
"id": "DDDD"
}
},
{
"relationshipType": "child",
"service": {
"id": "xxxxxxxx"
}
}
],
"id": "yyyyy"
}
]
}
}
expected:
{
"rows" : [ {
"rowdata" : {
"relationshipType" : "child",
"Name" : "yy",
"id" : "yyyyy"
}
} ]
}

Mongo Aggregation using $Max

I have a collection that stores history, i.e. a new document is created every time a change is made to the data, I need to extract fields based on the max value of a date field, however my query keeps returning either all of the dates or requires me to push the fields into an array which make the data hard to analyze for an end-user.
Expected output as CSV:
MAX(DATE), docID, url, type
1579719200216, 12371, www.foodnetwork.com, food
1579719200216, 12371, www.cnn.com, news,
1579719200216, 12371, www.wikipedia.com, info
Sample Doc:
{
"document": {
"revenueGroup": "fn",
"metaDescription": "",
"metaData": {
"audit": {
"lastModified": 1312414124,
"clientId": ""
},
"entities": [],
"docId": 1313943,
"url": ""
},
"rootUrl": "",
"taggedImages": {
"totalSize": 1,
"list": [
{
"image": {
"objectId": "woman-reaching-for-basket",
"caption": "",
"url": "",
"height": 3840,
"width": 5760,
"owner": "Facebook",
"alt": "Woman reaching for basket"
},
"tags": {
"totalSize": 4,
"list": []
}
}
]
},
"title": "The 8 Best Food Items of 2020",
"socialTitle": "The 8 Best Food Items of 2020",
"primaryImage": {
"objectId": "woman-reaching-for-basket.jpg",
"caption": "",
"url": "",
"height": 3840,
"width": 5760,
"owner": "Hero Images / Getty Images",
"alt": "Woman reaching for basket in laundry room"
},
"subheading": "Reduce your footprint with these top-performing diets",
"citations": {
"list": []
},
"docId": 1313943,
"revisionId": "1313943_1579719200216",
"templateType": "LIST",
"documentState": {
"activeDate": 579719200166,
"state": "ACTIVE"
}
},
"url": "",
"items": {
"totalSize": "",
"list": [
{
"type": "recipe",
"data": {
"comInfo": {
"list": [
{
"type": "food",
"id": "https://www.foodnetwork.com"
}
]
},
"type": ""
},
"id": 4,
"uuid": "1313ida-qdad3-42c3-b41d-223q2eq2j"
},
{
"type": "recipe",
"data": {
"comInfo": {
"list": [
{
"type": "news",
"id": "https://www.cnn.com"
},
{
"type": "info",
"id": "https://www.wikipedia.com"
}
]
},
"type": "PRODUCT"
},
"id": 11,
"uuid": "318231jc-da12-4475-8994-283u130d32"
}
]
},
"vertical": "food"
}
Below query:
db.collection.aggregate([
{
$match: {
vertical: "food",
"document.documentState.state": "ACTIVE",
"document.templateType": "LIST"
}
},
{
$unwind: "$document.items"
},
{
$unwind: "$document.items.list"
},
{
$unwind: "$document.items.list.contents"
},
{
$unwind: "$document.items.list.contents.list"
},
{
$match: {
"document.items.list.contents.list.type": "recipe",
"document.revenueGroup": "fn"
}
},
{
$sort: {
"document.revisionId": -1
}
},
{
$group: {
_id: {
_id: {
docId: "$document.docId",
date: {$max: "$document.revisionId"}
},
url: "$document.items.list.contents.list.data.comInfo.list.id",
type: "$document.items.list.contents.list.data.comInfo.list.type"
}
}
},
{
$project: {
_id: 1
}
},
{
$sort: {
"document.items.list.contents.list.id": 1, "document.revisionId": -1
}
}
], {
allowDiskUse: true
})
First of all, you need to go through the documentation of the $group aggregation here.
you should be doing this instead:
{
$group: {
"_id": "$document.docId"
"date": {
$max: "$document.revisionId"
},
"url": {
$first: "$document.items.list.contents.list.data.comInfo.list.id"
},
"type": {
$first:"$document.items.list.contents.list.data.comInfo.list.type"
}
}
}
This will give you the required output.

"Client invalid path, not found in rest table" does anyone know what this Sabre's error means

I want to use this API service:
https://developer.sabre.com/docs/read/rest_apis/air/book/create_passenger_name_record
and the server responds with this json:
{
"status": "NotProcessed",
"type": "Application",
"errorCode": "ERR.2SG.CLIENT.INVALID_REQUEST",
"timeStamp": "2017-09-12T13:21:29.522-05:00",
"message": "Client invalid path, not found in rest table"
}
As mentioned in the comments, the endpoint is not right. After fixing that you'd get many different errors, for example you are referencing a Profile ID ABCDEF that doesn't exist.
I've modified that request so you'd get a successful response.
v2.0.0/passenger/records?mode=create
{
"CreatePassengerNameRecordRQ": {
"targetCity": "XXXX",
"TravelItineraryAddInfo": {
"AgencyInfo": {
"Ticketing": {
"TicketType": "7TAW/"
}
},
"CustomerInfo": {
"ContactNumbers": {
"ContactNumber": [
{
"Phone": "817-555-1212",
"PhoneUseType": "H"
}
]
},
"PersonName": [
{
"GivenName": "TEST",
"Surname": "TEST"
}
]
}
},
"AirBook": {
"OriginDestinationInformation": {
"FlightSegment": [
{
"ArrivalDateTime": "2018-07-20T14:20",
"DepartureDateTime": "2018-07-20T12:57",
"FlightNumber": "2404",
"NumberInParty": "1",
"ResBookDesigCode": "Y",
"Status": "NN",
"DestinationLocation": {
"LocationCode": "LAX"
},
"MarketingAirline": {
"Code": "AA",
"FlightNumber": "2404"
},
"MarriageGrp": "O",
"OriginLocation": {
"LocationCode": "DFW"
}
}
]
}
},
"AirPrice": {
"PriceRequestInformation": {
"OptionalQualifiers": {
"PricingQualifiers": {
"PassengerType": [
{
"Code": "ADT",
"Quantity": "1"
}
]
}
}
}
},
"MiscSegment": {
"DepartureDateTime": "2018-10-29",
"NumberInParty": 1,
"Status": "NN",
"Type": "OTH",
"OriginLocation": {
"LocationCode": "LAS"
},
"Text": "TEST",
"VendorPrefs": {
"Airline": {
"Code": "AA"
}
}
},
"SpecialReqDetails": {
"AddRemark": {
"RemarkInfo": {
"FOP_Remark": {
"Type": "CHECK",
"CC_Info": {
"Suppress": true,
"PaymentCard": {
"AirlineCode": "YY",
"CardSecurityCode": "1234",
"Code": "VI",
"ExpireDate": "2012-12",
"ExtendedPayment": "12",
"ManualApprovalCode": "123456",
"Number": "4123412341234123",
"SuppressApprovalCode": true
}
}
},
"Remark": [
{
"Type": "Historical",
"Text": "TEST HISTORICAL REMARK"
},
{
"Type": "Invoice",
"Text": "TEST INVOICE REMARK"
},
{
"Type": "Itinerary",
"Text": "TEST ITINERARY REMARK"
},
{
"Type": "Hidden",
"Text": "TEST HIDDEN REMARK"
}
]
}
},
"AirSeat": {
"Seats": {
"Seat": [
{
"NameNumber": "1.1",
"Preference": "AN",
"SegmentNumber": "1"
}
]
}
},
"SpecialService": {
"SpecialServiceInfo": {
"Service": [
{
"SSR_Code": "OSI",
"PersonName": {
"NameNumber": "1.1"
},
"Text": "TEST",
"VendorPrefs": {
"Airline": {
"Code": "UA"
}
}
}
]
}
}
},
"PostProcessing": {
"RedisplayReservation": true,
"EndTransaction": {
"Source": {
"ReceivedFrom": "SWS TEST"
}
}
}
}
}

How can I use CloudKit web services to query based on a reference field?

I've got two CloudKit data objects that look somewhat like this:
Parent Object:
{
"records": [
{
"recordName": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
"recordType": "ParentObject",
"fields": {
"fsYear": {
"value": "2015",
"type": "STRING"
},
"displayOrder": {
"value": 2015221153856287200,
"type": "INT64"
},
"fjpFSGuidForReference": {
"value": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
"type": "STRING"
},
"fsDateSearch": {
"value": "2015221153856287158",
"type": "STRING"
},
},
"recordChangeTag": "id4w7ivn",
"created": {
"timestamp": 1439149087571,
"userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
"deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
},
"modified": {
"timestamp": 1439149087571,
"userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
"deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
}
}
],
"total":
}
Child Object:
{
"records": [
{
"recordName": "2015221153856287168",
"recordType": "ChildObject",
"fields": {
"District": {
"value": "002",
"type": "STRING"
},
"ZipCode": {
"value": "12345",
"type": "STRING"
},
"InspecReference": {
"value": {
"recordName": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
"action": "NONE",
"zoneID": {
"zoneName": "_defaultZone"
}
},
"type": "REFERENCE"
},
},
"recordChangeTag": "id4w7lew",
"created": {
"timestamp": 1439149090856,
"userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
"deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
},
"modified": {
"timestamp": 1439149090856,
"userRecordName": "_0d26968032e31bbc72c213037b6cb35d",
"deviceID": "A19CD995FDA3093781096AF5D818033A241D65C1BFC3D32EC6C5D6B3B4A9AA6B"
}
}
],
"total": 1
}
I'm trying to write a query to directly access the CloudKit web service and return the Child Object based on the reference of the parent object.
My test JSON looks something like this:
{"query":{"recordType":"ChildObject","filterBy":{"fieldName":"InspecReference","fieldValue":{ "value" : "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57", "type" : "string" },"comparator":"EQUALS"}},"zoneID":{"zoneName":"_defaultZone"}}
However, I'm getting the following error from CloudKit:
{"uuid":"33db91f3-b768-4a68-9056-216ecc033e9e","serverErrorCode":"BAD_REQUEST","reason":"BadRequestException:
Unexpected input"}
I'm guessing I have the Record Field Dictionary in the query wrong. However, the documentation isn't clear on what this should look like on a reference object.
You have to re-create the actual object of the reference. In this particular case, the JSON looks like this:
{
"query": {
"recordType": "ChildObject",
"filterBy": {
"fieldName": "InspecReference",
"fieldValue": {
"value": {
"recordName": "14102C0A-60F2-4457-AC1C-601BC628BF47-184-000000012D225C57",
"action": "NONE"
},
"type": "REFERENCE"
},
"comparator": "EQUALS"
}
},
"zoneID": {
"zoneName": "_defaultZone"
}
}