Problem with the The draft orders not being created via admin API.

Solved

Problem with the The draft orders not being created via admin API.

desmonic
Shopify Partner
2 0 0

Hello.   It is our first try with Shopify API.   We want to Create Draft Orders via Shopify ADMIN API and although we can get response back about how many draft orders are open (count) and what those are, when we try to create a draft order we get response 200 and  ERROR.   We are on Laravel Framework.   (the code is below)

 

in the store backend, we see message 

"Some of your custom apps and/or admin webbook subscriptions may not work as expected because they are using deprecated API versions. etc etc etc."   Our code is below and it appears we use version 2023-07

 

 

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use Gnikyt\BasicShopifyAPI\BasicShopifyAPI;
use Gnikyt\BasicShopifyAPI\Options;
use Gnikyt\BasicShopifyAPI\Session;

class OrderController extends Controller
{
    public function index()
    {
        return 'Order Index Page';
    }

    public function draft(Request $request)
    {
        echo 'Draft Order ...<br>';
        // Create options for the API
        $options = new Options();
        $options->setVersion('2023-07');

        // Create the client and session
        $api = new BasicShopifyAPI($options);
/////////////////
 $api->setSession(new Session('XXXXXXXX', 'XXXXXXXxxxXXX'>

        

 // Create a draft order
        $param = [
            'draft_order' => [
                'line_items' => [
                    [
                        'title' => 'Basketball',
                        'price' => 1.00,
                        'quantity' => 1,
                        'grams' => 50,
                    ]
                ],
                'tax_lines' => [
                    [
                        'price' => 1.00,
                        'rate' => 0.08,
                        'title' => 'HST'
                    ]
                ],
                'transactions' => [
                    [
                        'amount' => 1.00,
                        'kind' => 'sale',
                        'status' => 'success',
                    ]
                ],
                'total_tax' => 0.08,
                'currency' => 'USD',
            ]
        ];

        echo 'Create draft order: <br>';
        print_r($param);
        echo '<br>';

         $result = $api->rest('POST', '/admin/api/2023-07/draft_orders.json', $param);
        if ($result) {
            if ($result['status'] == 201) {
                //print_r($result['body']->container['draft_orders']);
                echo '<br>Create draft order success<br>';
            } else {
                echo 'Error: ' . $result['errors'] . ', status: ' . $result['status'] . '<br>';
            }
        } else {
            echo 'Network error<br>';
        }

 

 

Our developer is using https://github.com/gnikyt/Basic-Shopify-API

 

Accepted Solution (1)

Marslan
Shopify Partner
48 5 15

This is an accepted solution.

There is sample PHP code in the docs, did you try that?
Also some of those params don't look valid.

Need some help or work done? DM me!

View solution in original post

Reply 1 (1)

Marslan
Shopify Partner
48 5 15

This is an accepted solution.

There is sample PHP code in the docs, did you try that?
Also some of those params don't look valid.

Need some help or work done? DM me!