How to place an order using Magento2 API? - api

I am looking for the complete "happy path" to place an order using Magento2's REST API. So far these are all the steps I have followed. What else am I missing?
Create a user: [POST] /rest/V1/customers
Log In (create a token): [POST] /rest/V1/integration/customer/token
Get Product Categories for navigation: [GET] /rest/V1/categories
Get Products:
4.1 Get Category Products: [GET] /rest/V1/categories/{category_id}/products
4.2 Or search for a product: [GET] /rest/V1/products
Create a cart: [POST] /rest/V1/carts/mine
Add items to cart: [POST] /rest/V1/carts/mine/items
Get cart payment information [GET] /rest/V1/carts/mine/payment-information
...
What other things do I have to do to place the order?

create empty cart
url : http://www.xxxxxx.com/rest/V1/carts/mine
call: post
response: cartID eg: 4290
Add item to the cart
url : http://www.xxxxxx.com/rest/V1/carts/mine/items
body:
{"cartItem":{
"sku":"JFCO00017","qty":1,"name":"Devil May Cry III 3 Dante Cosplay Costume","price":81.55,"product_type":"simple","quote_id":"4290","product_option":{"extension_attributes":{"custom_options":[{"option_id":"thumbnail","option_value":"\/d\/e\/devilmaycryiii3dantecosplay_1_.jpg"},{"option_id":"color_2","option_value":"Red"},{"option_id":"google_size","option_value":"xxs"}]}}}
}
Add billling info
url : http://www.xxxxxx.com/rest/V1/carts/mine/billing-address
body:
{
"address": {
"city": "noida",
"company": "iprag",
"countryId": "IN",
"email": "manish+2#gmail.com",
"firstname": "Manish",
"lastname": "Kumar",
"postcode": "201301",
"region": "UP",
"saveInAddressBook": 1,
"street": ["D-84"],
"telephone": "8802xxxx90"
},
"useForShipping": true
}
get shipping-methods
url : http://www.xxxxxx.com/rest/V1/carts/mine/shipping-methods
{
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed",
"amount": 10,
"base_amount": 10,
"available": true,
"error_message": "",
"price_excl_tax": 10,
"price_incl_tax": 10
}
add shipping info
url : http://www.xxxxxx.com/rest/V1/carts/mine/shipping-information
body:
{
"addressInformation": {
"billingAddress": {
"city": "noida",
"company": "iprag",
"email": "nkn#gmail.com",
"firstname": "Manish",
"lastname": "Kumar",
"postcode": "335001",
"region": "UP",
"street": ["D-84"],
"telephone": "9413433217"
},
"shippingAddress": {
"city": "noida",
"company": "iprag",
"email": "nkn#gmail.com",
"firstname": "Manish",
"lastname": "Kumar",
"postcode": "335001",
"region": "UP",
"street": ["D-84"],
"telephone": "9413433217"
},
"shippingCarrierCode": "flatrate",
"shippingMethodCode": "flatrate"
}
}
response: payment method and cart detail
Order place
URL : http://www.xxxxxx.com/rest/V1/carts/mine/order
body :
{
"paymentMethod":{"method":"checkmo"},
"shippingMethod":
{
"method_code":"flatrate",
"carrier_code":"flatrate",
"additionalProperties":{}
}
}
response: orderid

Ok, I finally got it right.
Save payment information and create order [POST] /rest/V1/carts/mine/payment-information

Related

Microsoft Booking Appointment Graph API -Only Post Request Not working

when I trying to create Microsoft Booking Appointment through Graph API
Only Post Request Not working .
GET , PATCH , DELETE Reuqest are working fine
through postman
same post request is working find on graph explorer platform . but not on posmant with
my auth token
my post API
https://graph.microsoft.com/v1.0/solutions/bookingBusinesses/XXXXXXXXXXXXXXX.com/appointments
and body (took example from here)
excluded optional properties like servicename and customers
{
"#odata.type": "#microsoft.graph.bookingAppointment",
"customerTimeZone": "America/Chicago",
"smsNotificationsEnabled": false,
"endDateTime": {
"#odata.type": "#microsoft.graph.dateTimeTimeZone",
"dateTime": "2023-01-02T14:30:00.0000000",
"timeZone": "UTC"
},
"isLocationOnline": true,
"optOutOfCustomerEmail": false,
"anonymousJoinWebUrl": null,
"postBuffer": "PT10M",
"preBuffer": "PT5M",
"price": 10,
"priceType#odata.type": "#microsoft.graph.bookingPriceType",
"priceType": "fixedPrice",
"reminders#odata.type": "#Collection(microsoft.graph.bookingReminder)",
"reminders": [
{
"#odata.type": "#microsoft.graph.bookingReminder",
"message": "This service is tomorrow",
"offset": "P1D",
"recipients#odata.type": "#microsoft.graph.bookingReminderRecipients",
"recipients": "allAttendees"
},
{
"#odata.type": "#microsoft.graph.bookingReminder",
"message": "Please be available to enjoy your lunch service.",
"offset": "PT1H",
"recipients#odata.type": "#microsoft.graph.bookingReminderRecipients",
"recipients": "customer"
},
{
"#odata.type": "#microsoft.graph.bookingReminder",
"message": "Please check traffic for next cater.",
"offset": "PT2H",
"recipients#odata.type": "#microsoft.graph.bookingReminderRecipients",
"recipients": "staff"
}
],
"serviceId": "XXXXXXXXXXXXXXXXXXXXX",
"serviceLocation": {
"#odata.type": "#microsoft.graph.location",
"address": {
"#odata.type": "#microsoft.graph.physicalAddress",
"city": "Buffalo",
"countryOrRegion": "USA",
"postalCode": "98052",
"postOfficeBox": null,
"state": "NY",
"street": "123 First Avenue",
"type#odata.type": "#microsoft.graph.physicalAddressType",
"type": null
},
"coordinates": null,
"displayName": "Customer location",
"locationEmailAddress": null,
"locationType#odata.type": "#microsoft.graph.locationType",
"locationType": null,
"locationUri": null,
"uniqueId": null,
"uniqueIdType#odata.type": "#microsoft.graph.locationUniqueIdType",
"uniqueIdType": null
},
"serviceNotes": "Customer requires punctual service.",
"startDateTime": {
"#odata.type": "#microsoft.graph.dateTimeTimeZone",
"dateTime": "2023-01-02T14:00:00.0000000",
"timeZone": "UTC"
},
"maximumAttendeesCount": 1,
"filledAttendeesCount": 1
}

Swagger API having different response with the change of Optional Parameters

I am trying to create the OAS Swagger documentation for an existing API where the response for the API is changing on the basis of Query parameter. I am struggling to document this in a developer friendly way, so need some assistance. Below is the complete scenario for your reference.
EndPoint 1 : /order?expand=false
/order?expand=false
{
"orderNo": "12345",
"orderDetail": "Description of Order",
"orderMarket": {
"id": "UK"
},
"brandOrderStatus": {
"id": "LLA"
}
}
Endpoint 2 : /order?expand=true
{
"orderNo": "12345",
"orderDetail": "Description of Order",
"orderMarket": {
"id": "UK",
"descr": "United Kingdom",
"lang": "en-GB"
},
"brandOrderStatus": {
"id": "LLA",
"descr": "Some Status Description",
"lang": "en-GB"
}
}
Endpoint 3 : /order?expand=true&include=feature
{
"orderNo": "12345",
"orderDetail": "Description of Order",
"orderMarket": {
"id": "UK",
"descr": "United Kingdom",
"lang": "en-GB"
},
"brandOrderStatus": {
"id": "LLA",
"descr": "Some Status Description",
"lang": "en-GB"
}
"_embedded": {
"features": [
{
"id": "AJS",
"type": "FeatureType",
"descr": "FeatureDescription",
"prices": [
{
"type": "msrpNetPrice",
"amount": 0.00,
"currency": "GBP"
}
],
"group": "null"
}
]
}
}
I tried using OneOf, but don't really think that will work in this case as the structure is changing with every optional parameter.
Any thoughts as how this can be documented in Swagger documentation ? Or any other idea to get this documented.

Get nested data c.<type>.<type> in SQL Query?

I've been searching everywhere for this seemingly simple action: I'd like to select only a certain few data type from a nested source.
The closest that I can get to the solution is this:
SELECT c.receipt_number, c.millitime, c.email, c.phone, c.shipping, c.shipping_note, c.amount_paid, i.description, i.quantity
FROM c
JOIN i IN c.line_items
WHERE c.millitime > 1627813253000
But this will create lots of duplicated data, like the receipt_number, email, etc in the example:
[
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"description": "Curry Chicken",
"quantity": 1
},
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"description": "Chicken Noodle",
"quantity": 8
}
]
Is there a way to create a nested result of c.line_items with just the desired data description and quantity? The final result should be similar to:
[
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"line_items": [
{
"description": "Chicken Noodle",
"quantity": 8
},
{
"description": "Curry Chicken",
"quantity": 1
}
]
}
]
I have created the same in
You can use distinct keyword to remove duplicates from the results.
Add c.line_items to your select list and change i.description, i.quantity to c.description, c.quantity to add view under line_items.
Query:
SELECT distinct c.receipt_number, c.millitime, c.email, c.phone, c.shipping, c.shipping_note, c.amount_paid, c.line_items
FROM c
JOIN i IN c.line_items
WHERE c.millitime > 1627813253000
Result:
Reference: Azure Cosmos DB SQL query - JSON items

Dynamic values in Rest API using JMeter

I have payload POST call:
{
"tenantName":"loki",
"owner":
{
"country": "india",
"firstName": "raj",
"lastName": "kumar",
"locale": "in",
"organization": "softwareag",
"phone": "9789155778",
"title": "mr",
"userName": "raraj#softwareag.com",
"email": "raraj#softwareag.com",
"password":"V2VsY29tZUAxMjM0"
},
"products": [
"cumulocity",
"b2b"
]
}
In that payload, the tenant name is unique, How to pass different values for each post call?
You can use __RandomString to randomize name, for example 5 lower case letters:
${__RandomString(5,abcdefghijklmnopqrstuvwxyz,)}
RandomString function returns a random String of length using characters in chars to use
Or load name values from CSV Data set config
You can use __groovy() function in order to call RandomStringUtils.randomAlphabetic() method like:
${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(4),)}
replace 4 with the number of your choice to make the random string shorter or longer
The function can be inlined directly into your request body
{
"tenantName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(4),)}",
"owner": {
"country": "india",
"firstName": "raj",
"lastName": "kumar",
"locale": "in",
"organization": "softwareag",
"phone": "9789155778",
"title": "mr",
"userName": "raraj#softwareag.com",
"email": "raraj#softwareag.com",
"password": "V2VsY29tZUAxMjM0"
},
"products": [
"cumulocity",
"b2b"
]
}
More information: Apache Groovy - Why and How You Should Use It

How to process payments with service fee being deducted in Visa Cybersource Payments API?

I have an app that I would like to add payment processing similar to Amazon payment processing into it where sub-merchants get paid by customers with service fee being deducted, I can see in https://developer.visa.com/capabilities/cybersource/reference#cybersource__cybs_payments_v2__v2__process_a_payment the following request body but there is no field in request body to specify a service fee:
{
"clientReferenceInformation": {
"code": "TC588171_3"
},
"processingInformation": {
"commerceIndicator": "internet"
},
"aggregatorInformation": {
"subMerchant": {
"cardAcceptorID": "1234567890",
"country": "US",
"phoneNumber": "650-432-0000",
"address1": "900 Metro Center",
"postalCode": "94404-2775",
"locality": "Foster City",
"name": "Visa Inc",
"administrativeArea": "CA",
"region": "PEN",
"email": "test#cybs.com"
},
"name": "V-Internatio",
"aggregatorID": "123456789"
},
"orderInformation": {
"billTo": {
"country": "US",
"lastName": "VDP",
"address2": "Address 2",
"address1": "201 S. Division St.",
"postalCode": "48104-2201",
"locality": "Ann Arbor",
"administrativeArea": "MI",
"firstName": "RTS",
"phoneNumber": "999999999",
"district": "MI",
"buildingNumber": "123",
"company": "Visa",
"email": "test#cybs.com"
},
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD"
}
},
"paymentInformation": {
"card": {
"expirationYear": "2031",
"number": "5555555555554444",
"securityCode": "123",
"expirationMonth": "12",
"type": "002"
}
}
}
Is there a way or a workaround to get a service fee deducted?
Service fees go in the orderInformation block. Like this:
"orderInformation": {
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD",
"serviceFeeAmount": "3.00"
},
There are a few prerequisites to using service fees. One of which you must be using First Data as your processor. For more details check this documentation.