OrdersCreate Endpoint

Overview

Nearly every single store needs orders.  This endpoint allows you to create as many orders as you want.

Requirements

The following pre-requisites will be necessary to accomplish the goals of this article:

  • General understanding of REST and API’s
  • Understanding of C# and/or JavaScript
  • Visual Studio 2012 or newer

Getting Started

You should already have a project open and ready to accept code to allow you to use this REST API endpoint.  You should also have some kind of idea what attributes that you want your order to have before you create it.

OrdersCreate

This REST API endpoint allows you to create an order for your store. 

Example URL

This is what the REST endpoint will look like if you are calling it using JavaScript.  See our REST API URL documentation for more information.

http://example.com/DesktopModules/Hotcakes/API/rest/v1/orders

HTTP Method

POST

Parameters

This method only requires that you pass an instance of the OrderDTO object to the endpoint.

Returns

If successful, this endpoint will return a OrderDTO object in JSON format.  Otherwise, you will have one or more errors returned.

Example Code

The following code will allow you to successfully call this endpoint, provided that you have enabled it.

Project References

  • Hotcakes.CommerceDTO

Import Namespaces

  • Hotcakes.CommerceDTO.v1
  • Hotcakes.CommerceDTO.v1.Client
  • Hotcakes.CommerceDTO.v1.Orders

 

string url = "http://example.com";
string key = "YOUR-API-KEY";

Api proxy = new Api(url, key);

// create a new order object
var order = new OrderDTO();

// add billing information
order.BillingAddress = new AddressDTO
{
    AddressType = AddressTypesDTO.Billing,
    City = "West Palm Beach",
    CountryBvin = "BF7389A2-9B21-4D33-B276-23C9C18EA0C0",
    FirstName = "John",
    LastName = "Dough",
    Line1 = "319 N. Clematis Street",
    Line2 = "Suite 500",
    Phone = "561-228-5319",
    PostalCode = "33401",
    RegionBvin = "7EBE4F07-A844-47B8-BDA8-863DDDF5C778"
};

// add at least one line item
order.Items = new List<LineItemDTO>();
order.Items.Add(new LineItemDTO
{
    ProductId = "dfcae0ee-8bcf-4321-8b31-7883b5434285",
    Quantity = 1
});

// add the shipping address
order.ShippingAddress = new AddressDTO();
order.ShippingAddress = order.BillingAddress;
order.ShippingAddress.AddressType = AddressTypesDTO.Shipping;

// specify who is creating the order
order.UserEmail = "info@hotcakescommerce.com";
order.UserID = "1";
            
// call the API to create the order
ApiResponse<OrderDTO> response = proxy.OrdersCreate(order);
// your domain name
var url = "http://example.com"; 
// the path where the API is
var apiPath = "/DesktopModules/Hotcakes/API/rest/v1/";  
// endpoint as shown in the documentation
var endPoint = "orders";  
// get this from the store admin
var apiKey = "YOUR-API-KEY";

$(document).ready(function() {

    // create a new order object
    var order = {
        "BillingAddress": {
            "AddressType": 1,
            "City": "West Palm Beach",
            "CountryBvin": "BF7389A2-9B21-4D33-B276-23C9C18EA0C0",
            "FirstName": "John",
            "LastName": "Dough",
            "Line1": "319 N. Clematis Street",
            "Line2": "Suite 500",
            "Phone": "561-228-5319",
            "PostalCode": "33401",
            "RegionBvin": "7EBE4F07-A844-47B8-BDA8-863DDDF5C778"
        },
        "Items": [
            {
                "ProductId": "dfcae0ee-8bcf-4321-8b31-7883b5434285",
                "Quantity": 1
            }
        ],
        "ShippingAddress": {
            "AddressType": 2,
            "City": "West Palm Beach",
            "CountryBvin": "BF7389A2-9B21-4D33-B276-23C9C18EA0C0",
            "FirstName": "John",
            "LastName": "Dough",
            "Line1": "319 N. Clematis Street",
            "Line2": "Suite 500",
            "Phone": "561-228-5319",
            "PostalCode": "33401",
            "RegionBvin": "7EBE4F07-A844-47B8-BDA8-863DDDF5C778"
        },
        "UserEmail": "info@hotcakescommerce.com",
        "UserID": "1"
    };

    // call the API to find all orders in the store
    $.ajax({
        dataType: "json",
        url: url + apiPath + endPoint + "?key=" + apiKey,
        data: JSON.stringify(order),
        type: 'POST',
        success: function (data) {
            // do something
        },
        error: function(jqXHR, textStatus) {
            // do something else
        }
    });

});
{
   "Errors":[

   ],
   "Content":{
      "Coupons":[

      ],
      "Items":[
         {
            "Id":25,
            "StoreId":1,
            "LastUpdatedUtc":"\/Date(1406671991878)\/",
            "BasePricePerItem":0,
            "DiscountDetails":[

            ],
            "OrderBvin":"f8e72ad2-6f8b-4914-a09b-d46af5276286",
            "ProductId":"dfcae0ee-8bcf-4321-8b31-7883b5434285",
            "VariantId":"",
            "ProductName":"",
            "ProductSku":"",
            "ProductShortDescription":"",
            "Quantity":1,
            "QuantityReturned":0,
            "QuantityShipped":0,
            "ShippingPortion":0,
            "StatusCode":"",
            "StatusName":"",
            "TaxRate":0,
            "TaxPortion":0,
            "SelectionData":[

            ],
            "IsNonShipping":false,
            "TaxSchedule":0,
            "ProductShippingWeight":0,
            "ProductShippingLength":0,
            "ProductShippingWidth":0,
            "ProductShippingHeight":0,
            "CustomProperties":[
               {
                  "DeveloperId":"hcc",
                  "Key":"ismarkedforfreeshipping",
                  "Value":"False"
               },
               {
                  "DeveloperId":"hcc",
                  "Key":"istaxexempt",
                  "Value":"False"
               },
               {
                  "DeveloperId":"hcc",
                  "Key":"freeshippingmethodsids",
                  "Value":""
               }
            ],
            "ShipFromMode":0,
            "ShipFromNotificationId":"",
            "ShipFromAddress":{
               "Bvin":null,
               "LastUpdatedUtc":"\/Date(1406671991288)\/",
               "StoreId":0,
               "NickName":"",
               "FirstName":"",
               "MiddleInitial":"",
               "LastName":"",
               "Company":"",
               "Line1":"",
               "Line2":"",
               "Line3":"",
               "City":"",
               "RegionName":"",
               "RegionBvin":"",
               "PostalCode":"",
               "CountryName":"United States",
               "CountryBvin":"bf7389a2-9b21-4d33-b276-23c9c18ea0c0",
               "Phone":"",
               "Fax":"",
               "WebSiteUrl":"",
               "UserBvin":"",
               "AddressType":0
            },
            "ShipSeparately":false,
            "ExtraShipCharge":0
         }
      ],
      "Notes":[

      ],
      "Packages":[

      ],
      "Id":10,
      "Bvin":"f8e72ad2-6f8b-4914-a09b-d46af5276286",
      "StoreId":1,
      "LastUpdatedUtc":"\/Date(1406671991875)\/",
      "TimeOfOrderUtc":"\/Date(1406671991281)\/",
      "OrderNumber":"",
      "ThirdPartyOrderId":"",
      "UserEmail":"info@hotcakescommerce.com",
      "UserID":"1",
      "CustomProperties":[
         {
            "DeveloperId":"hcc",
            "Key":"ApplyVATRules",
            "Value":"False"
         }
      ],
      "PaymentStatus":0,
      "ShippingStatus":0,
      "IsPlaced":false,
      "StatusCode":"",
      "StatusName":"",
      "BillingAddress":{
         "Bvin":null,
         "LastUpdatedUtc":"\/Date(1406671991282)\/",
         "StoreId":0,
         "NickName":"",
         "FirstName":"John",
         "MiddleInitial":"",
         "LastName":"Dough",
         "Company":"",
         "Line1":"319 N. Clematis Street",
         "Line2":"Suite 500",
         "Line3":"",
         "City":"West Palm Beach",
         "RegionName":"",
         "RegionBvin":"7EBE4F07-A844-47B8-BDA8-863DDDF5C778",
         "PostalCode":"33401",
         "CountryName":"",
         "CountryBvin":"BF7389A2-9B21-4D33-B276-23C9C18EA0C0",
         "Phone":"561-228-5319",
         "Fax":"",
         "WebSiteUrl":"",
         "UserBvin":"",
         "AddressType":1
      },
      "ShippingAddress":{
         "Bvin":null,
         "LastUpdatedUtc":"\/Date(1406671991282)\/",
         "StoreId":0,
         "NickName":"",
         "FirstName":"John",
         "MiddleInitial":"",
         "LastName":"Dough",
         "Company":"",
         "Line1":"319 N. Clematis Street",
         "Line2":"Suite 500",
         "Line3":"",
         "City":"West Palm Beach",
         "RegionName":"",
         "RegionBvin":"7EBE4F07-A844-47B8-BDA8-863DDDF5C778",
         "PostalCode":"33401",
         "CountryName":"",
         "CountryBvin":"BF7389A2-9B21-4D33-B276-23C9C18EA0C0",
         "Phone":"561-228-5319",
         "Fax":"",
         "WebSiteUrl":"",
         "UserBvin":"",
         "AddressType":1
      },
      "AffiliateID":null,
      "FraudScore":0,
      "Instructions":"",
      "ShippingMethodId":"",
      "ShippingMethodDisplayName":"",
      "ShippingProviderId":"",
      "ShippingProviderServiceCode":"",
      "TotalTax":0,
      "ItemsTax":0,
      "ShippingTax":0,
      "ShippingTaxRate":0,
      "TotalShippingBeforeDiscounts":0,
      "TotalHandling":0,
      "OrderDiscountDetails":[

      ],
      "ShippingDiscountDetails":[

      ]
   }
}
Have more questions? Submit a request

Need More Help?

Do you need more assistance with this article? Please review your support options.