Create an order using the Orders API

Hi,

I am trying to create an order using the API as shown here https://developer.squareup.com/docs/orders-api/build-with-orders

The problem is always I am getting an error like
Exception when calling OrdersApi->createOrder:[HTTP/2 401] {“errors”: [{“code”: “UNAUTHORIZED”,“detail”: “This request could not be authorized.”,“category”: “AUTHENTICATION_ERROR”}]} which obviously is an authentication issue.

Can someone guide me to a right direction please?

That error normally happens if the credentials and base path URL aren’t configured correctly to the environment you are targeting. Is this in production or sandbox you are trying to create the order?

It is a sandbox, and I am using the location ID and the Sandbox Application ID, am I missing something? Where do I have to set base path URL?

With CreateOrder you’ll need to pass the sandbox access token in the header of the request. Also the base path URL is connect.squareupsandbox.com. :slightly_smiling_face:

I am confused, just trying to use the code sample from here https://developer.squareup.com/docs/orders-api/build-with-orders

I just copy/paste the entire code changing my credentials, but for the path?

Were did you get the link to that page? The information on the page isn’t correct. :slightly_frowning_face: It has you get the application ID but the code sample is asking for the access token. The getting started for orders is in the Create Orders of our Documentation site.

What is that code sample in that page for then?
OK, trying to explain in depth. I am trying to create an order within Square from a woocommerce website that is connected already with square. So when a order is placed through the website, everything goes pretty well, transaction showing up on square account dashboard, BUT NOT AS AN ORDER, SO I NEED TO CREATE THE ORDER BASED UPON THE ORDER FROM THE WEBSITE.

What approach should I use?

That code looks like it’s from our deprecated SDKs. Was there a public site that provided the link to the page?

If the payment is showing in the Transactions section of the Dashboard from a completed payment from the WooCommerce integration you unfortunately won’t be able to add an order_id to the payment because one is already associated to the payment. At this time only orders that have a fulfillment and have been fully paid for will show in the Orders section of the Dashboard.

The order is paid in full.

Right, but a fulfillment is also required for it to show in the Orders section of the Dashboard. If the WooCommerce isn’t creating the order with the fulfillment then it won’t show in Orders.

Appreciate, any code sample doing fulfillment using php? The fulfillment needs to be before creating an order or after?

The order can be updated with a fulfillment with UpdateOrder if it’s not completed. I believe that all the orders from the WooCommerce integration are completed if you aren’t using delay capture. I you are using delay capture you would need to get the order from the payment and add a fulfillment then capture the payment.

Yes indeed all orders through WC are completed and look for a solution to populate the Orders in Square with orders from WC and not sure where should I start.

Unfortunately this is a limitation with the WooCommerce integration and they will need to add fulfillments to orders to have them all show in the Orders section of the Dashboard. :slightly_smiling_face:

I was able to connect and create order through PHP, even getting the square order id , but still cannot see the order on dev dashboard.

That’s great that you were able to create the order. Is the order paid for and does it have a fulfillment?

The order created is hard coded not taken from a user input, also I am able to retrieve the orders using the API, but for no reason they don’t show up on Square dashboard. I do not know what to do. Yes it has fulfillment.

What’s the order_id so I can take a look? :slightly_smiling_face:

Xzf7LeOVByyu1BmgSC2Xma6AF2WZY

The order isn’t paid for and that is why it’s not showing in the Dashboard. :slightly_smiling_face: