All things Shopify and commerce
hello i am using REST API in php.
I have a problem when creating an order (draft) despite the fact that I give a discount in accordance with doc. the discount is not suitable.
I am sending something like this:
{
"email": "testujedarek@pocztavp.pl",
"line_items": [
{
"variant_id": "31626267426921",
"quantity": "3",
"applied_discount": {
"value_type": "fixed_amount",
"value": 142,
"amount": 426,
"title": "Promo",
"description": "Promo"
}
}
],
"shipping_address": {
"first_name": "Darek",
"last_name": "Test",
"address1": "Test 1",
"phone": "123123123",
"city": "Test",
"zip": "12-123",
"country": "Poland"
},
"shipping_line": {
"title": "Kurier",
"price": 0
}
}
There is someone who can help me.
Thanks!!
Hi @pstanek
I checked your issue and thought the problem could have been caused by missing data when you created the draft order.
This is a sample data that Shopify provides
HTTP/1.1 201 Created
{
"draft_order": {
"id": 1069920475,
"note": null,
"email": null,
"taxes_included": false,
"currency": "USD",
"invoice_sent_at": null,
"created_at": "2022-10-03T12:19:47-04:00",
"updated_at": "2022-10-03T12:19:47-04:00",
"tax_exempt": false,
"completed_at": null,
"name": "#D5",
"status": "open",
"line_items": [
{
"id": 1066630380,
"variant_id": 447654529,
"product_id": 921728736,
"title": "IPod Touch 8GB",
"variant_title": "Black",
"sku": "IPOD2009BLACK",
"vendor": "Apple",
"quantity": 1,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"fulfillment_service": "shipwire-app",
"grams": 567,
"tax_lines": [
{
"rate": 0.05,
"title": "GST",
"price": "9.95"
},
{
"rate": 0.08,
"title": "Tax",
"price": "15.92"
}
],
"applied_discount": null,
"name": "IPod Touch 8GB - Black",
"properties": [],
"custom": false,
"price": "199.00",
"admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1066630380"
}
],
"shipping_address": null,
"billing_address": null,
"invoice_url": "https://jsmith.myshopify.com/548380009/invoices/d0730281ac9692b04a064b4bac5f23bc",
"applied_discount": null,
"order_id": null,
"shipping_line": null,
"tax_lines": [
{
"rate": 0.05,
"title": "GST",
"price": "9.95"
},
{
"rate": 0.08,
"title": "Tax",
"price": "15.92"
}
],
"tags": "",
"note_attributes": [],
"total_price": "224.87",
"subtotal_price": "199.00",
"total_tax": "25.87",
"presentment_currency": "USD",
"total_line_items_price_set": {
"shop_money": {
"amount": "199.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "199.00",
"currency_code": "USD"
}
},
"total_price_set": {
"shop_money": {
"amount": "224.87",
"currency_code": "USD"
},
"presentment_money": {
"amount": "224.87",
"currency_code": "USD"
}
},
"subtotal_price_set": {
"shop_money": {
"amount": "199.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "199.00",
"currency_code": "USD"
}
},
"total_tax_set": {
"shop_money": {
"amount": "25.87",
"currency_code": "USD"
},
"presentment_money": {
"amount": "25.87",
"currency_code": "USD"
}
},
"total_discounts_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"total_shipping_price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"payment_terms": null,
"admin_graphql_api_id": "gid://shopify/DraftOrder/1069920475",
"customer": null
}
}
You can double-check your data and refer to this material: https://shopify.dev/api/admin-rest/2022-10/resources/draftorder#post-draft-orders.
Feel free to let me know if you need any further help.
If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here ☕.
B2B Solution & Custom Pricing | Product Labels by BSS
Need help from our expert? Kindly share your request with us via community@bsscommerce.com
only until it worked until November 8 and then suddenly stopped.
and check this solution
in documentacion write is:
[
{
"variant_id": "31626267426921", "quantity": "3",
}
]
i Add,
"applied_discount": { "value_type": "fixed_amount", "value": 142, "amount": 426, "title": "Promo", "description": "Promo" }
More i not need, Anyway, they are not required. What you gave is not a batch data, but a response ...
Hi @pstanek
You can try again with the following data: (wrap the draft_order attribute outside, change the variant_id to match the store)
{
"draft_order":{
"email": "testujedarek@pocztavp.pl",
"line_items": [
{
"variant_id": "39635639107745",
"quantity": "3",
"applied_discount": {
"value_type": "fixed_amount",
"value": 142,
"amount": 426,
"title": "Promo",
"description": "Promo"
}
}
],
"shipping_address": {
"first_name": "Darek",
"last_name": "Test",
"address1": "Test 1",
"phone": "123123123",
"city": "Test",
"zip": "12-123",
"country": "Poland"
},
"shipping_line": {
"title": "Kurier",
"price": 0
}
}
}
I tested it, and it's successful. The following is the result:
{
"draft_order": {
"id": 926101668001,
"note": null,
"email": "testujedarek@pocztavp.pl",
"taxes_included": true,
"currency": "EUR",
"invoice_sent_at": null,
"created_at": "2022-11-09T09:08:12+00:00",
"updated_at": "2022-11-09T09:08:12+00:00",
"tax_exempt": false,
"completed_at": null,
"name": "#D50",
"status": "open",
"line_items": [
{
"id": 57353938403489,
"variant_id": 39635639107745,
"product_id": 6664666513569,
"title": "All In One Snail Repair Cream",
"variant_title": "75ml",
"sku": "MIZ-13AL1SNLRPR-F",
"vendor": "Mizon",
"quantity": 3,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"fulfillment_service": "manual",
"grams": 150,
"tax_lines": [
{
"rate": 0.21,
"title": "Tax",
"price": "0.00"
}
],
"applied_discount": {
"description": "Promo",
"value": "142.0",
"title": "Promo",
"amount": "90.00",
"value_type": "fixed_amount"
},
"name": "All In One Snail Repair Cream - 75ml",
"properties": [],
"custom": false,
"price": "30.00",
"admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/57353938403489"
}
],
"shipping_address": {
"first_name": "Darek",
"address1": "Test 1",
"phone": "123123123",
"city": "Test",
"zip": "12-123",
"province": null,
"country": "Poland",
"last_name": "Test",
"address2": null,
"company": null,
"latitude": null,
"longitude": null,
"name": "Darek Test",
"country_code": "PL",
"province_code": null
},
"billing_address": null,
"invoice_url": "https://development-service-1.myshopify.com/55931240609/invoices/96162a151298a30bc5cb3e68aa742a60",
"applied_discount": null,
"order_id": null,
"shipping_line": {
"title": "Kurier",
"custom": true,
"handle": null,
"price": "0.00"
},
"tax_lines": [
{
"rate": 0.21,
"title": "Tax",
"price": "0.00"
},
{
"rate": 0.21,
"title": "Tax",
"price": "0.00"
}
],
"tags": "",
"note_attributes": [],
"total_price": "0.00",
"subtotal_price": "0.00",
"total_tax": "0.00",
"payment_terms": null,
"admin_graphql_api_id": "gid://shopify/DraftOrder/926101668001",
"customer": {
"id": 6401438875809,
"email": "testujedarek@pocztavp.pl",
"accepts_marketing": false,
"created_at": "2022-11-09T09:04:52+00:00",
"updated_at": "2022-11-09T09:04:52+00:00",
"first_name": "Darek",
"last_name": "Test",
"orders_count": 0,
"state": "disabled",
"total_spent": "0.00",
"last_order_id": null,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"tags": "",
"last_order_name": null,
"currency": "EUR",
"phone": null,
"accepts_marketing_updated_at": "2022-11-09T09:04:52+00:00",
"marketing_opt_in_level": null,
"tax_exemptions": [],
"email_marketing_consent": {
"state": "not_subscribed",
"opt_in_level": "single_opt_in",
"consent_updated_at": null
},
"sms_marketing_consent": null,
"admin_graphql_api_id": "gid://shopify/Customer/6401438875809",
"default_address": {
"id": 7689759129761,
"customer_id": 6401438875809,
"first_name": "Darek",
"last_name": "Test",
"company": null,
"address1": "Test 1",
"address2": null,
"city": "Test",
"province": null,
"country": "Poland",
"zip": "12-123",
"phone": "123123123",
"name": "Darek Test",
"province_code": null,
"country_code": "PL",
"country_name": "Poland",
"default": true
}
}
}
}
I hope this can help you.
If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here ☕.
B2B Solution & Custom Pricing | Product Labels by BSS
Need help from our expert? Kindly share your request with us via community@bsscommerce.com
I still have a bug
i send
{
"email": "3eb4obnt63953452mxzacq5r@pocztavp.pl",
"line_items": [
{
"variant_id": "42826415341822",
"quantity": "3",
"applied_discount": {
"value_type": "fixed_amount",
"value": 149,
"amount": 447,
"title": "Promo",
"description": "Promo"
}
}
],
"shipping_address": {
"first_name": "test",
"last_name": "test",
"address1": "test1",
"phone": "121212",
"city": "test",
"zip": "testt",
"country": "Poland"
},
"shipping_line": {
"title": "Kurier",
"price": 0
}
}
i useed
https://github.com/phpclassic/php-shopify and ani Version 2022-01
Hi @pstanek
I see that your data still does not have the "draft_order" attribute, you can copy the following code and run it again:
{
"draft_order":{
"email": "3eb4obnt63953452mxzacq5r@pocztavp.pl",
"line_items": [
{
"variant_id": "42826415341822",
"quantity": "3",
"applied_discount": {
"value_type": "fixed_amount",
"value": 149,
"amount": 447,
"title": "Promo",
"description": "Promo"
}
}
],
"shipping_address": {
"first_name": "test",
"last_name": "test",
"address1": "test1",
"phone": "121212",
"city": "test",
"zip": "testt",
"country": "Poland"
},
"shipping_line": {
"title": "Kurier",
"price": 0
}
}
}
If you still have a bug, I suggest you to check call API with Postman software. Thanks
If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here ☕.
B2B Solution & Custom Pricing | Product Labels by BSS
Need help from our expert? Kindly share your request with us via community@bsscommerce.com
I found a bug.
The discount is removed when sending only "note_attributes".
So when posting a "note_attributes" I have to send it once it's line_iteam and is work.
"draft_order" attribute it is injected directly by the library php so it's not here.
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024