Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tariqbilal's avatar

DraftOrder Add Line items Shopify API

Has anyone worked with laravel shopify,

https://github.com/Kyon147/laravel-shopify

I was wondering if I can add products on draft order via API. Is it possible any help would be great.

0 likes
3 replies
realrandyallen's avatar

Putting together the pieces of the puzzle it seems possible, using the package you can send a REST api call to the shopify API:

https://github.com/Kyon147/laravel-shopify/wiki/Usage#accessing-api-for-the-current-shop

$shop = Auth::user();
$response = $shop->api()->rest('PUT', '/admin/api/2023-10/draft_orders/DRAFT_ORDER_ID.json', [ 'line_items' => [
      {
        "product_id": 921728736,
        "title": "IPod Touch 8GB",
        "sku": "IPOD2009BLACK",
        "vendor": "Apple",
        "quantity": 1,
        "price": "199.00"
      }
    ]]);
dd($response);

Use Shopify's documentation to know what you need to send along with the request:

https://shopify.dev/docs/api/admin-rest/2023-10/resources/draftorder#put-draft-orders-draft-order-id

tariqbilal's avatar

@realrandyallen thanks for replying, but unfortunately it's not working.

I am getting this response.

Client error: PUT https://{url}/admin/api/2023-10/draft_orders/DRAFT_ORDER_ID.jsonresulted in a400 Bad Request response:\n {"errors":{"draft_order":"Required parameter missing or invalid"}

Maybe use Mutation for this? I have been trying for few days not an no success any help would be highly appreciated.

realrandyallen's avatar

@tariqbilal You need to change DRAFT_ORDER_ID.json to whatever your actual draft order id is, i.e. if the draft order id is 994118539 your url would be:

/admin/api/2023-10/draft_orders/994118539.json

1 like

Please or to participate in this conversation.