Build with Orders API
Build with Orders API to create orders for itemized transactions and inventory tracking.
To build with the Orders API, the following must be true:
You have a Square account enabled for payment processing. If you have not enabled payment processing on your account (or you are not sure), visit squareup.com/activation.
You are using HTTPS. HTTPS is required for all production Square API calls. HTTP calls are only supported for developing and testing on localhost.
A hosting solution that allows you to create dynamic pages with server side scripting (e.g., PHP, Ruby, ASP, Java). If your hosting solution only supports HTML, you cannot use the Orders API at this time.
If you are building an app using OAuth, you need the
ORDERS_WRITEpermission to create orders and the
ORDERS_READpermission to retrieve orders.
Additionally this guide makes the following assumptions:
You have read the introductory review of this API.
You can create and run websites on localhost or a development server. If you are new to testing web pages locally, you should read Run Local Web Servers before continuing.
You are familiar with basic web development. If you are new to web development, you should read Getting started with the Web by Mozilla.org before continuing.
You are familiar with HTTPS. If this is your first time working with HTTPS, consider reading the TLS and HTTPS Overview.
To use the steps in this topic, you need:
Your application ID. Find your application ID on the Credentials page of your Square application in the Developer Dashboard.
An active location ID. Copy a developer account location ID from the Locations page of your Square application in the Developer Dashboard or set the Developer Dashboard to Sandbox mode and then copy a Sandbox location ID.
Order requests must include at least 1 line item. You can create line items that reference an existing catalog, or you can create an ad-hoc line item.
For now, we will create an ad-hoc line item because it is faster to get started with ad-hoc line items. However, we strongly recommend that you create line items by referencing catalog IDs.
Order object using your ad-hoc line item.
Item names must match exactly to make the best use of Square's reporting with ad-hoc items. For example, "Red Dog Collar: Leather", "Red Dog Collar - Leather", "Red Dog collar Leather", and "Red Dog Collar - Leather" are all considered different items because the strings use different punctuation, whitespace, and capitalization.
You can avoid issues with item names by referencing catalog IDs instead. Note that orders can have both ad-hoc and catalog line items.
Create the Order request object and send it to the CreateOrder endpoint. For now, we will print the raw result to the screen.
Note that Orders require an idempotency key.