Example #1
0
        /// <summary>
        /// Update the order based on orderId
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="updatedOrder"></param>
        /// <returns></returns>
        public bool UpdateOrder(int orderId, PrintfulOrder updatedOrder)
        {
            PrintfulRequestResult result = null;
            try
            {
                if (updatedOrder == null)
                {
                    throw new PrintfulException("No order supplied for the updated order!");
                }
                string url = Printful.ApiUrl + "orders/" + orderId;
                result = SendRequest(url, updatedOrder.ToJson(), "PUT");
                result.DeserializeRawBody();
            }
            catch (Exception e)
            {
                _printful.LastErrorMessage = e.Message;
                if (_printful.LetExceptionsBubble)
                {
                    throw;
                }
            }

            if (result != null)
            {
                return result.Success;
            }
            return false;
        }
Example #2
0
        /// <summary>
        /// Serialize and send the order to Printful
        /// </summary>
        /// <param name="order"></param>
        /// <returns>true on success, false on failure</returns>
        public bool CreateOrder(PrintfulOrder order)
        {
            PrintfulRequestResult result = null;
            try
            {
                string jsonToSend = order.ToJson();
                string url = Printful.ApiUrl + "orders";

                result = SendRequest(url, jsonToSend, "POST");
                result.DeserializeRawBody();
            }
            catch (Exception e)
            {
                _printful.LastErrorMessage = e.Message;
            }

            if (result != null)
            {
                return result.Success;
            }
            return false;
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Printful API Test");

            PrintfulOrder order = new PrintfulOrder(1);
            order.Handling = PrintfulShippingHandling.STANDARD;

            order.Items = new List<PrintfulItem>();
            PrintfulItem shirt = new PrintfulItem();
            shirt.ImageUrl = "http://example.com/shirt.pdf";
            shirt.Name = "Test Shirt";
            shirt.ProductId = 302; //2001 fine jersey short sleeve men, xl red
            shirt.Sku = 1222333;
            shirt.Quantity = 2;
            order.Items.Add(shirt);

            PrintfulItem poster = new PrintfulItem();
            poster.ImageUrl = "http://www.example.com/poster.pdf";
            poster.Name = "Test Poster";
            poster.ProductId = 2; //24x36 unframed
            poster.Sku = 123456;
            poster.Quantity = 1;
            order.Items.Add(poster);

            order.Notes = "Items for hackathon booth!";
            order.Recipient = new PrintfulRecipient();
            order.Recipient.FullName = "Tes Ter";
            order.Recipient.AddressLine1 = "123 Test Ave";
            order.Recipient.AddressLine2 = "Suite 205";
            order.Recipient.City = "Philadelphia";
            order.Recipient.State = "PA";
            order.Recipient.Zip = "19019";
            order.Recipient.Country = "US";

            Console.WriteLine("Testing JSON parsing...");
            Console.WriteLine(order.ToJson());
            Console.WriteLine();

            Printful print = new Printful("sjk81fow-60v6-6z6r:vqi6-r78f8jxdrnhm");
            print.LetExceptionsBubble = true;
            print.VerboseLogging = true;
            try
            {
                Console.WriteLine("Testing order creation...");
                Console.WriteLine("Order created successfully? " + print.Orders.CreateOrder(order));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing order status...");
                order.Items.Remove(poster);
                Console.WriteLine("Order status: " + print.Orders.OrderStatus(1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing order update...");
                order.Items.Remove(poster);
                Console.WriteLine("Order updated successfully? " + print.Orders.UpdateOrder(1, order));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing order status...");
                order.Items.Remove(poster);
                Console.WriteLine("Order status: " + print.Orders.OrderStatus(1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing order deletion...");
                Console.WriteLine("Order deleted successfully? " + print.Orders.DeleteOrder(1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing order status...");
                order.Items.Remove(poster);
                Console.WriteLine("Order status: " + print.Orders.OrderStatus(1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing GetAllProducts...");
                string products = print.Products.GetAllProducts();
                Console.WriteLine(products);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                Console.WriteLine("Testing GetProduct...");
                string products = print.Products.GetProduct("poster", "{test}");
                Console.WriteLine(products);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();
            Console.WriteLine(print.Information);
            

            Console.ReadKey();
        }