PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 2, 2022

[FIXED] How to Create Shopify Order Via Api using Php?

 July 02, 2022     api, php, shopify     No comments   

Issue

I am trying to Create a Shopify Order using Api this is my code :

            $arrOrder= array(
              "email"=> "foo@example.com",
              "fulfillment_status"=> "fulfilled",
              "send_receipt"=> true,
              "send_fulfillment_receipt"=> true,
              "line_items"=> array(
                array(
                  "product_id"=>875744960642,
                  "variant_id"=> 3558448932592,
                  "quantity"=> 1
                )
            ),
                "customer"=> array(
                  "id"=> 458297751235
                ),
                "financial_status"=> "pending"
              
            
            );            echo json_encode($arrOrder);
            echo "<br />";
            $url = "https://AkiKey:Password@Store.myshopify.com/admin/api/2021-01/orders.json";
            
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_VERBOSE, 0);
            curl_setopt($curl, CURLOPT_HEADER, 1);
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($arrOrder));
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            $response = curl_exec($curl);
            curl_close($curl);
            echo "<pre>";
            print_r($response);
and the response is : {"errors":{"order":"Required parameter missing or invalid"}}


Solution

I think there is some data mismatch that is sent using API Call, according to the documentation this the format to create an order. enter image description here

So I think your request is something like this one demo code

$arrOrder= [
   "order" =>[
      "email"                    => "foo@example.com",
      "fulfillment_status"       => "fulfilled",
      "send_receipt"             => true,
      "send_fulfillment_receipt" => true,
      "line_items" => [
         [
            "product_id" => 875744960642,
            "variant_id" => 3558448932592,
            "quantity"   => 1
         ]
      ],
      "customer" => [
                     "id"=> 458297751235
                ],
      "financial_status"=> "pending"
   ]
];


Answered By - Onkar
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing