create order with different extra bag for outbound and inbound - amadeus

I want to test order create API by adding extra bags. And I am experiencing a strange problem.
I make a search for Paris-NYC round trip, then I send the request to offer price API using include=detailed-fare-rules,bags parameter.
In the response, I get 2 kinds of extra bag information:
1 bag, 30 EUR
2 bags, 75 EUR
"bags": {
"1": {
"quantity": 1,
"name": "CHECKED_BAG",
"price": {
"amount": "30.00",
"currencyCode": "EUR"
},
"bookableByItinerary": true,
"segmentIds": [
"1",
"3"
],
"travelerIds": [
"1"
]
},
"2": {
"quantity": 2,
"name": "CHECKED_BAG",
"price": {
"amount": "75.00",
"currencyCode": "EUR"
},
"bookableByItinerary": true,
"segmentIds": [
"1",
"3"
],
"travelerIds": [
"1"
]
}
}
Everything goes well if I create order by:
adding 1 bag for outbound(paris to NYC), and adding 1 bag for inbound(NYC to Paris)
adding only 1 bag for outbound (0 extra bag for inbound)
adding 2 bag for outbound(paris to NYC), and adding 2 bags for inbound(NYC to Paris)
The problem is for the scenario:
I create order by adding 1 bag for outbound, and adding 2 bags for inbound.
In this case, the order is created with a warning message
"warnings": [
{
"status": 200,
"code": 0,
"title": "BookingWithPriceMarginWarning",
"detail": "The prices are lower than expected"
}
]
And the created order contains 1 extra bag for outbound, and 1 extra bag for inbound.
So I have 2 questions about this strange problem:
Is it normal that my order is modified when processing order create ?
Adding different number of extra bags for different itineraries is supported ?
Thanks

Is it normal that my order is modified when processing order create ?
It depends if you are Self-Service or Enterprise user:
For Enterprise users, Flight Create Orders offer the possibility to do a "best-effort" for additional-service booking. If this option is activated, Flight Create Orders gives priority to the reservation of your flight and remove the additional service that cannot be booked. That's why you receive the warning in your request when it happens.
Self Service users have the default behavior which rejects the creation of the order if at least one additional service can not be booked. In this case you will receive the following error:
{
"errors": [
{
"status": 400,
"code": 38034,
"title": "ONE OR MORE SERVICES ARE NOT AVAILABLE",
"detail": "Error booking additional services"
}
]
}
Adding different number of extra bags for different itineraries is supported ?
Yes, that is supported. Be aware that you cannot have an infinite amount of bag on a plane, so it could happen that you get an error when adding extra bags if there are too many bags already added by other passengers.

Related

Add computed field to Query in Grafana using JSON API als data source

What am I trying to achieve:
I would like to have a time series chart showing the total number of members in my club at any time. This member count should be calculated by using the field "Eintrittsdatum" (joining-date) and "Austrittsdatum" (leaving-date). I’m thinking of it as a running sum - every filled field with a joining-date means +1 on the member count, every leaving-date entry is a -1.
Data structure
I’m calling the API of webling.ch with a secret key. This is my data structure with sample data per member:
[
{
"type": "member",
"meta": {
"created": "2020-03-02 11:33:00",
"createuser": {
"label": "Joana Doe",
"type": "user"
},
"lastmodified": "2022-12-06 16:32:56",
"lastmodifieduser": {
"label": "Joana Doe",
"type": "user"
}
},
"readonly": true,
"properties": {
"Mitglieder ID": 99,
"Anrede": "Dear",
"Vorname": "Jon",
"Name": "Doe",
"Strasse": "Doeington Street",
"Adresszusatz": null,
"PLZ": "9999",
"Ort": "Doetown",
"E-Mail": "jon.doe#doenet.net",
"Telefon Privat": null,
"Telefon Geschäft": null,
"Mobile": "099 877 54 54",
"Geschlecht": "m",
"Geburtstag": "1966-03-10",
"Mitgliedschaftstyp": "Aktivmitgliedschaft",
"Eintrittsdatum": "2020-03-01",
"Austrittsdatum": null,
"Passfoto": null,
"Wordpress Benutzername": null,
"Wohnhaft im Glarnerland": false,
"Lat": "43.1563379",
"Long": "6.0474622"
},
"parents": [
240
],
"children": {
},
"links": {
"debitor": [
2124,
3056,
3897
],
"attendee": [
2576
]
},
"id": 1815
}
]
Grafana data source
I am using the “JSON API” by Marcus Olsson: GitHub - grafana/grafana-json-datasource: A data source plugin for loading JSON APIs into Grafana.
Grafana v9.3.1 (89b365f8b1) on Linux
My current approach
Queries:
Query C - uses a filter on the source-API to only show entries with "Eintrittsdatum" IS NOT EMPTY
Field 1 (alias "datum") has a JSONata-Query of:
properties.Eintrittsdatum
Field 2 (alias "names") should return the full name and has a query of:
$map($.properties, function($v) {(
($v.Vorname&" "&$v.Name);
)})
Field 3 (alias "value") should return "1" for every entry and has a query of:
$map($.properties, function($v) {(
(1);
)})
Query D - uses a filter on the source-API to only show entries with "Austrittsdatum" IS NOT EMPTY
Field 1 (alias "datum") has a JSONata-Query of:
properties.Austrittsdatum
Field 2 (alias "names") should return the full name and has a query of:
$map($.properties, function($v) {(
($v.Vorname&" "&$v.Name);
)})
Field 3 (alias "value") should return "1" for every entry and has a query of:
$map($.properties, function($v) {(
(1);
)})
Here's a screenshot to clarify things
(https://zigerschlitzmakers.ch/wp-content/uploads/2023/01/ScreenshotGrafana-1.png)
Transformations:
My applied transformations
(https://zigerschlitzmakers.ch/wp-content/uploads/2023/01/ScreenshotGrafana-2.png)
What's working
I can correctly gather the number of members added/subtracted per day.
What's not working
I can't get the graph to display the way i want: I'd like to have a running sum of these numbers instead of the following two graphs.
Time series graph with merged queries
(https://zigerschlitzmakers.ch/wp-content/uploads/2023/01/ScreenshotGrafana-3.png)
Time series graph with unmerged queries
(https://zigerschlitzmakers.ch/wp-content/uploads/2023/01/ScreenshotGrafana-4.png)
I can't get the names to display within the tooltip of the data points (really not THAT necessary).

How to get a product / variant "committed" inventory?

Problem:
On the Shopify Admin, section Products > Inventory, there's a "committed" inventory.
Based on my comprehension it means "reserved stock for pending orders", or "inventory reserved by orders created but not yet completed".
This "committed" stock value can be very useful for stock updates by app. But pratically this value seems hard to retreive.
Question:
How to get this "committed" inventory value in an efficient way ?
Current state of researchs :
Not possible via Shopify APIs (REST & GraphQL, version 2022-07)
Can be approximated (not sure it's the right method) by looping over all unfulfilled orders, and sum up (by variant) the unfulfilled product variant quantity. However, it takes time and consumes a lot of API resources.
According to a Shopify Community Manager (ref. post)
The Committed inventory state isn't added to the API currently.
It's possible now in the 2023-01 version of the API. The InventoryLevel got a new field quantities, which returns this for a product with a total stock of 10 and two sold:
[
{
"quantity": 8,
"name": "available"
},
{
"quantity": 2,
"name": "committed"
},
{
"quantity": 0,
"name": "incoming"
},
{
"quantity": 10,
"name": "on_hand"
},
{
"quantity": 0,
"name": "reserved"
}
]

Querying Line Items of Order with JSON Functions in BigQuery

I am banging my head head here for the past 2 hours with all the available JSON_... functions in BigQuery. I've read quite a few questions here but no matter why I try, I never succeed in extracting the "amounts" from my JSON below.
This is my JSON stored in a BQ column:
{
"lines": [
{
"id": "70223039-83d6-463d-a482-7ce4d50bf0fc",
"charges": [
{
"type": "price",
"amount": 50.0
},
{
"type": "discount",
"amount": -40.00
}
]
},
{
"id": "70223039-83d6-463d-a482-7ce4d50bf0fc",
"charges": [
{
"type": "price",
"amount": 20.00
},
{
"type": "discount",
"amount": 0.00
}
]
}
]
}
Imagine the above being an order containing multiple items.
I am trying to get a sum of all amounts => 50-40+20+0. The result needs to be 30 = the total order price.
Is it possible to pull all the amount values and then have them summed up just via SQL without any custom JS functions? I guess the summing is the easy part - getting the amounts into an array is the challenge here.
Use below
select (
select sum(cast(json_value(charge, '$.amount') as float64))
from unnest(json_extract_array(order_as_json, '$.lines')) line,
unnest(json_extract_array(line, '$.charges')) charge
) total
from your_table
if applied to sample data in y our question - output is

mongoDB: aggregation which adds a field of counting field in the collection

I am new to MongoDb and have a query which I am struggling with..
I have a collection of reported users which looks like this:
{
"_id": 1,
"userId": 1,
"reason": "some reason",
"date": "2017-07-22"
}
I need a query which will add to each report the number of reports for that userId.
meaning if the collection has 3 records with userId=1. the query will return three records and each of them will also include a field
count=3 meaning the record above will now look like this:
{
"_id": 1
"userId": 1,
"reason": "some reason",
"date": "2017-07-22",
"count": 3
}
I tried using $project and $addFields aggregations but was not able to add a field which is a result of a query over the whole collection.
any ideas?
The answer provided by Veeram is correct, just that if you are running mongodb version less than 3.6, in the last stage of aggregate you might want to replace the $replaceRoot operator with a $project
aggregate([
{$group:{_id:"$userId", "data":{"$push":"$$ROOT"}, count:{$sum:1} } },
{"$unwind":"$data"},
{$project:{_id:"$data._id", userId:"$data.userId", reason:"$data.reason", date:"$data.date", count:1}}
])

Restkit to-many relationship append to set instead of setting a new set

I have a iOS Restkit related question. I have a parent-child relationship data coming from a remote server and map those object to a NSManagedObject object with Restkit. The problem that I am currently having is every request to the server always wipe out the "child" relationship and replace it with the new data coming from the server. Is there a way to avoid those and append the new child instead?
For example: I have a classic Category --> Products relationship.
{"categories": [
{
"cat_id": "1",
"cat_title": "category 1",
"cat_tag": 1,
"product": [
{
"prod_id": "1",
"prod_name": "product 1",
"prod_tag": 1
},
{
"prod_id": "2",
"prod_name": "product 2",
"prod_tag": 1
}
]
}
] }
And that works fine and everything is saved properly with the relationship on the CoreData. But if I make another request to the server and have a new response:
{"categories": [
{
"cat_id": "1",
"cat_title": "category 1",
"cat_tag": 1,
"product": [
{
"prod_id": "3",
"prod_name": "product 3",
"prod_tag": 1
},
{
"prod_id": "4",
"prod_name": "product 4",
"prod_tag": 1
}
]
}
] }
I will have product 3 and product 4 replace product 1 and product 2 on the database. I am sure I setup all the relationship and primary key correctly. (Both cat_id and prod_id are set as a primary key).
Having investigated through the RestKit's internal framework, I noticed that around line 576 in the RKObjectMappingOperation class, there is
RKLogTrace(#"Mapped NSSet relationship object from keyPath '%#' to
'%#'. Value: %#", relationshipMapping.sourceKeyPath,
relationshipMapping.destinationKeyPath, destinationObject);
NSMutableSet *destinationSet = [self.destinationObject
mutableSetValueForKey:relationshipMapping.destinationKeyPath];
[destinationSet setSet:destinationObject];
So I guess that is easy to just change
[destinationSet setSet:destinationObject];
to
[destinationSet addObjectsFromArray:[destinationObject allObjects]]
But I was wondering whether there is a better way to do it?
Cheers,
Thanks for the support from Reskit. It is now supported by RKRelationshipMapping.(https://github.com/RestKit/RestKit/issues/989)
Just set assignmentPolicy value of RKRelationshipMapping instance to RKUnionAssignmentPolicy