square / connect-csharp-sdk

C# client library for the Square Connect APIs
https://docs.connect.squareup.com/
Apache License 2.0
27 stars 25 forks source link

CreateOrder- LocationId remains null #124

Closed mmcc1 closed 5 years ago

mmcc1 commented 5 years ago

Trying to create an order, even with a valid locationId, results in the following error. Its like its not being set.

One or more errors occurred. (LocationId is a required property for Order and cannot be null): AggregateException at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

at Square.Connect.Model.Order..ctor(String Id, String LocationId, String ReferenceId, OrderSource Source, String CustomerId, List1 LineItems, List1 Taxes, List1 Discounts, List1 ServiceCharges, List1 Fulfillments, List1 Returns, OrderMoneyAmounts ReturnAmounts, OrderMoneyAmounts NetAmounts, OrderRoundingAdjustment RoundingAdjustment, List1 Tenders, List1 Refunds, String CreatedAt, String UpdatedAt, String ClosedAt, Nullable`1 State, Money TotalMoney, Money TotalTaxMoney, Money TotalDiscountMoney, Money TotalServiceChargeMoney) at CBAOrderCreate.Function.FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context) in C:\Clients\Comeback Cash\Code\CBAOrderCreate\CBAOrderCreate\Function.cs:line 219

mmcc1 commented 5 years ago

This is the calling code:

var apiInstance = new OrdersApi();
                        var body = new CreateOrderRequest(); 

                        body.Order = new Order();
                        body.Order.CustomerId = cr.CustomerId;
                        body.Order.LocationId = cr.locationId;

                        body.LineItems = new List<CreateOrderRequestLineItem>();

                        foreach (CreateNewLineOrderItem li in cr.LineOrderItems)
                        {
                            body.LineItems.Add(new CreateOrderRequestLineItem() { Name = li.Name, Quantity = li.Quantity.ToString(), CatalogObjectId = li.Id });
                        }

                        try
                        {

                            CreateOrderResponse result = apiInstance.CreateOrder(body.Order.LocationId, body);
                            return new APIGatewayProxyResponse
                            {
                                StatusCode = (int)HttpStatusCode.OK,
                                Body = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(result)),
                                Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
                            };
                        }
mmcc1 commented 5 years ago

Worked around this by not adding the locationId and giving it only to the method call. It works, but I've yet to find a way to generate a complete order.

mmcc1 commented 5 years ago

I tested this with the latest release and it is still an issue