Get all address of a customer using rest Magento2 - magento2

How to get all addresses of a customer using rest Magento2? Is there any out of the box API?

Yes there is, given you have the customer ID:
GET /V1/customers/{customerId}
this will return all the customer addresses
"customer":
{
"id": 0,
"default_billing": "string",
"default_shipping": "string",
"addresses": [
{
"id": 0,
"customer_id": 0,
"region": {
"region_code": "string",
"region": "string",
"region_id": 0,
"extension_attributes": {}
},
"region_id": 0,
"country_id": "string",
"street": [
"string"
]
}
]
}

Related

Select specific field inside a list from mongo collection

I have a collection with records in this format:
{
"data": [
{
"type": "UNKNOWN",
"ID": "UNKNOWN",
"payload": {
"value": -56,
"unit": "dBm"
}
},
{
"type": "UNKNOWN",
"ID": "UNKNOWN",
"payload": {
"value": -10,
"unit": "dBm"
}
}
]
}
Now is it possible to get only data[1].payload.value instead of returning the entire record?

Subtotal is not calculated correctly at order preview

I want to create a chatbot with Dialogflow and Google Assistant along with Google Transactions API for enabling a user to order some items. For now my agent contains the following four intents:
Default Welcome Intent (text response: Hello, do you want to buy a chocolate box?)
Default Fallback Intent
Int3 (training phrase: Yes, I want, fulfilment: enabled webhook)
Int4 (event: actions_intent_TRANSACTION_DECISION, fulfilment: enabled webhook)
I am using Dialogflow Json instead of Node.js to connect my agent with Transactions API. I want to build a cart and an order for the user by using finally that the user meets the transaction requirements by using the actions.intent.TRANSACTION_DECISION action of Google actions. For this reason, following Google docs, when Int3 is triggered I am using a webhook which connect Google Assistant my back-end which sends back the following json (to trigger actions.intent.TRANSACTION_DECISION) :
{
"fulfillmentText": "This is your order preview:",
"payload": {
"google": {
"expectUserResponse": true,
"isSsml": false,
"noInputPrompts": [],
"systemIntent": {
"data": {
"#type": "type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec",
"orderOptions": {
"requestDeliveryAddress": true
},
"paymentOptions": {
"actionProvidedOptions": {
"displayName": "VISA **** **** **** 3235",
"paymentType": "PAYMENT_CARD"
}
},
"proposedOrder": {
"cart": {
"lineItems": [
{
"description": "Book",
"id": "1",
"name": "Book",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 31
},
"type": "ACTUAL"
},
"quantity": 2,
"subLines": [],
"type": "REGULAR"
}
],
"merchant": {
"id": "Amazon",
"name": "Amazon"
},
"otherItems": []
},
"id": "<UNIQUE_ORDER_ID>",
"otherItems": [
{
"id": "Subtotal",
"name": "Subtotal",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 62
},
"type": "ACTUAL"
},
"type": "SUBTOTAL"
},
{
"id": "Delivery fees",
"name": "Delivery fees",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 10
},
"type": "ACTUAL"
},
"type": "FEE"
}
],
"totalPrice": {
"amount": {
"currencyCode": "USD",
"units": 72
},
"type": "ACTUAL"
}
}
},
"intent": "actions.intent.TRANSACTION_DECISION"
}
}
}
}
However, I am getting the following errors on Google Assistant simulator:
MalformedResponse
expected_inputs[0].possible_intents[0].input_value_data.transaction_decision_value_spec.proposed_order: subtotal price is not sum of regular lineItems. Expected-> Sum of line item price: units: 31 nanos: 0 currency: USD Actual-> Provided total price: units: 62 nanos: 0 currency: USD.
MalformedResponse
expected_inputs[0].possible_intents[0].input_value_data.transaction_decision_value_spec.proposed_order: total price is not sum of lineItems and otherItems. Expected-> Sum of line item price: units: 42 nanos: 0 currency: USD Actual-> Provided total price: units: 72 nanos: 0 currency: USD.
Why I am getting this error since I have specified that "quantity": 2 in the respective lineItem?
It is very obvious that the subtotal should be units: 62 since I have ordered "quantity": 2 products of units: 31 price each...
The final order preview looks like this (this is borrowed from Google docs examples):
The answer seems to be in the error message: the API expects a each line item's price to be a sum of the total items in that line item instead of a quantity price (relevant error phrase: "Sum of line item price"). The corrected JSON should look something like this:
{
"fulfillmentText": "This is your order preview:",
"payload": {
"google": {
"expectUserResponse": true,
"isSsml": false,
"noInputPrompts": [],
"systemIntent": {
"data": {
"#type": "type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec",
"orderOptions": {
"requestDeliveryAddress": true
},
"paymentOptions": {
"actionProvidedOptions": {
"displayName": "VISA **** **** **** 3235",
"paymentType": "PAYMENT_CARD"
}
},
"proposedOrder": {
"cart": {
"lineItems": [
{
"description": "Book",
"id": "1",
"name": "Book",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 62
},
"type": "ACTUAL"
},
"quantity": 2,
"subLines": [],
"type": "REGULAR"
}
],
"merchant": {
"id": "Amazon",
"name": "Amazon"
},
"otherItems": []
},
"id": "<UNIQUE_ORDER_ID>",
"otherItems": [
{
"id": "Subtotal",
"name": "Subtotal",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 62
},
"type": "ACTUAL"
},
"type": "SUBTOTAL"
},
{
"id": "Delivery fees",
"name": "Delivery fees",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 10
},
"type": "ACTUAL"
},
"type": "FEE"
}
],
"totalPrice": {
"amount": {
"currencyCode": "USD",
"units": 72
},
"type": "ACTUAL"
}
}
},
"intent": "actions.intent.TRANSACTION_DECISION"
}
}
}
}

Cloudant JSON data into dashdb table joins

I have successfully imported some JSON data into cloudant, the JSON data has three levels. Then created the dashdb warehouse from cloudant to put the data into relational tables. It appears that dashdb has created three tables for each of the levels in the JSON data but has not provided me with a Key to join back to the top level. Is there a customisation that is done somewhere that tells dashdb how to join the tables.
A sample JSON doc is below:
{
"_id": "579b56388aa56fd03a4fd0a9",
"_rev": "1-698183d4326352785f213b823749b9f8",
"v": 0,
"startTime": "2016-07-29T12:48:04.204Z",
"endTime": "2016-07-29T13:11:48.962Z",
"userId": "Ranger1",
"uuid": "497568578283117a",
"modes": [
{
"startTime": "2016-07-29T12:54:22.565Z",
"endTime": "2016-07-29T12:54:49.894Z",
"name": "bicycle",
"_id": "579b56388aa56fd03a4fd0b1",
"locations": []
},
{
"startTime": "2016-07-29T12:48:02.477Z",
"endTime": "2016-07-29T12:53:28.503Z",
"name": "walk",
"_id": "579b56388aa56fd03a4fd0ad",
"locations": [
{
"at": "2016-07-29T12:49:05.716Z",
"_id": "579b56388aa56fd03a4fd0b0",
"location": {
"coords": {
"latitude": -34.0418308,
"longitude": 18.3503616,
"accuracy": 37.5,
"speed": 0,
"heading": 0,
"altitude": 0
},
"battery": {
"is_charging": true,
"level": 0.7799999713897705
}
}
},
{
"at": "2016-07-29T12:49:48.488Z",
"_id": "579b56388aa56fd03a4fd0af",
"location": {
"coords": {
"latitude": -34.0418718,
"longitude": 18.3503895,
"accuracy": 33,
"speed": 0,
"heading": 0,
"altitude": 0
},
"battery": {
"is_charging": true,
"level": 0.7799999713897705
}
}
},
{
"at": "2016-07-29T12:50:20.760Z",
"_id": "579b56388aa56fd03a4fd0ae",
"location": {
"coords": {
"latitude": -34.0418788,
"longitude": 18.3503887,
"accuracy": 33,
"speed": 0,
"heading": 0,
"altitude": 0
},
"battery": {
"is_charging": true,
"level": 0.7799999713897705
}
}
}
]
},
{
"startTime": "2016-07-29T12:53:37.137Z",
"endTime": "2016-07-29T12:54:18.505Z",
"name": "carshare",
"_id": "579b56388aa56fd03a4fd0ac",
"locations": []
},
{
"startTime": "2016-07-29T12:54:54.112Z",
"endTime": "2016-07-29T13:11:47.818Z",
"name": "bus",
"_id": "579b56388aa56fd03a4fd0aa",
"locations": [
{
"at": "2016-07-29T13:00:08.039Z",
"_id": "579b56388aa56fd03a4fd0ab",
"location": {
"coords": {
"latitude": -34.0418319,
"longitude": 18.3503623,
"accuracy": 36,
"speed": 0,
"heading": 0,
"altitude": 0
},
"battery": {
"is_charging": false,
"level": 0.800000011920929
}
}
}
]
}
]
}
SQL for the three tables created in dashdb showing all the fields in each table is here. Note there is no FK that I can see, the "_ID" fields are unique to each table.
SELECT ENDTIME,STARTTIME,USERID,UUID,V,"_ID","_REV"
FROM <schemaname>.RANGER_DATA
where "_ID" = '579b56388aa56fd03a4fd0a9'
SELECT ARRAY_INDEX,ENDTIME,NAME,STARTTIME,TOTALPAUSEDMS,"_ID"
FROM <schemaname>.RANGER_DATA_MODES
where "_ID" = '579b56388aa56fd03a4fd0b1'
SELECT ARRAY_INDEX,AT,LOCATION_BATTERY_IS_CHARGING,LOCATION_BATTERY_LEVEL,LOCATION_COORDS_ACCURACY,LOCATION_COORDS_ALTITUDE,LOCATION_COORDS_HEADING,LOCATION_COORDS_LATITUDE,LOCATION_COORDS_LONGITUDE,LOCATION_COORDS_SPEED,RANGER_DATA_MODES,"_ID"
FROM <schemaname>.RANGER_DATA_MODES_LOCATIONS
where "_ID" = '579b56388aa56fd03a4fd0b0'
Cloudant uses _id for its UID for each document. It seems that the warehousing task iterates over these documents and assumes that there is a new document every time it sees a new _id.
Because you're using _id in your modes and locations this will produce an undesired result in the SQL DB.
Renaming your _id in modes and locations to something else should fix the problem.

Tax lines won't automatically generate in Shopify API order

I am posting the following to the Shopify API order endpoint:
{
"order": {
"email": "some#email.com",
"financial_status": "paid",
"fulfillment_status": null,
"send_receipt": true,
"send_fulfillment_receipt": true,
"note": "Created by somename",
"line_items": [
{
"variant_id": 21718275463,
"quantity": 1,
"price": 99,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717700871,
"quantity": 1,
"price": 1000,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717690055,
"quantity": 1,
"price": 555,
"requires_shipping": true,
"product_id": 6821668807
}
],
"processing_method": "offsite",
"shipping_address": {
"first_name": "Chris",
"address1": "10101 Musick Road",
"phone": "9999999999",
"city": "St. Louis",
"zip": "63123",
"province": "MO",
"country": "United States",
"last_name": "Becker",
"name": "Chris Becker",
"country_code": "US",
"province_code": "MO"
},
"source_name": "somename",
"taxes_included": false,
"shipping_lines": [
{
"title": "standard",
"price": 0.00,
"code": null,
"source": "brand owner on shopify",
"carrier_identifier": null,
"tax_lines": null
}
],
"tags": "some Order"
}
}
and receiving a response without tax lines that are filled. I have seen on the shopify forum that the taxlines are supposed to then be automatically
calculated and filled by shopify. I tried doing it with a customer as well but that didn't work either.
The Orders API will not auto-calculate the taxes but if your app knows how much they are then you can include this data using tax_lines and total_tax:
{
"order": {
"line_items": [{
"title": "Big Brown Bear Boots",
"price": 74.99,
"quantity": 3,
"tax_lines": [{
"price": 13.50,
"rate": 0.06,
"title": "State tax"
}]
}],
"total_tax": 13.50
}
}

How JSON format for calling Checking out REST Api of Broadleaf commerce looks like

I have followed setting up Broadleaf to make it running by following its documentation (http://docs.broadleafcommerce.org/current/REST-Tutorials.html). I wanted to do checking out the cart using REST Api; that's, /cart/checkout. Therefore, I looked inside the code in order to understand how the JSON format being sent will look alike. By looking through the code, I found that it is required to pass the JSON data as shown following:
{
"paymentInfo": {
"id": ,
"orderId": ,
"type": ,
"address": {
"id":
"firstname":
"lastname":
"addressLine1":
"addressLine2":
"city":
"state":
"country":
"postalCode":
},
"phone": "",
"additionalFields": "",
"amount": "",
"amountItems": "",
"customerIpAddress": "",
"referenceNumber": ""
},
"referenced": {
"id": "",
"referenceNumber": "",
"type": "",
"pan": "",
"cvvCode:" "",
"expirationMonth": "",
"expirationYear": "",
"accountNumber": "",
"routingNumber": "",
"pin": ""
}
}
However, I have no idea such the JSON data looks like. Therefore, if anyone who has ever used the api, please help me by showing an example of data in order to make the request. Looking forward to the answers.
Thanks in advance.
All of our REST APIs are exposed through a 'wrapper' concept. For instance, there is a CustomerWrapper, OrderWrapper, etc. These wrappers define which properties are serialized back and forth with the REST APIs.
For your specific case, you should look at PaymentReferenceMapWrapper.
{
"id": 1751,
"status": "IN_PROCESS",
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"totalShipping": {
"amount": "0.00",
"currency": "INR"
},
"subTotal": {
"amount": "860.00",
"currency": "INR"
},
"total": {
"amount": "860.00",
"currency": "INR"
},
"customer": {
"id": 2600
},
"orderItems": [
{
"id": 1752,
"name": "abc",
"quantity": 2,
"retailPrice": {
"amount": "430.00",
"currency": "INR"
},
"salePrice": {
"amount": "430.00",
"currency": "INR"
},
"orderId": 1751,
"categoryId": 10300,
"skuId": 10212,
"productId": 10212,
"isBundle": false,
"orderItemPriceDetails": [
{
"id": 1752,
"totalAdjustmentValue": {
"amount": "0.00",
"currency": "INR"
},
"totalAdjustedPrice": {
"amount": "860.00",
"currency": "INR"
},
"quantity": 2,
"adjustments": []
}
],
"isDiscountingAllowed": true
}
],
"fulfillmentGroups": [
{
"id": 1502,
"orderId": 1751,
"total": {
"amount": "860.00",
"currency": "INR"
},
"fulfillmentGroupItems": [
{
"id": 1752,
"fulfillmentGroupId": 1502,
"orderItemId": 1752,
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"quantity": 2,
"totalItemAmount": {
"amount": "860.00",
"currency": "INR"
}
}
]
}
],
"payments": [
{
"id": 601,
"orderId": 1751,
"type": "COD",
"amount": "860.00",
"currency": "INR",
"gatewayType": "Passthrough",
"transactions": [
{
"id": 601,
"orderPaymentId": 601,
"type": "AUTHORIZE_AND_CAPTURE",
"success": true,
"amount": "860.00",
"currency": "INR"
}
]
}
]
}
This is the same json you will get from /cart?customerId="" with method GET after successfully executing /cart/checkout/payment