Explore REST APIs In Invotide Part 2

In this series, we will be discussing the REST APIs in Invotide. In the first part, we went through the setup of API user credentials from the back-end. In this part, we'll extend it and go through the rest of the examples, showing how to set shipping, payment and customer related data in the cart. Finally, we'll conclude the article by placing an order!

If you haven't gone through the first part yet, we recommend that you go through it. Let's have a quick recap of what we've done so far in this series.

  • We created API user credentials from the back-end.
  • We set up the common file which is used in all the examples to make curl calls.
  • We went through the API usage by providing examples of "How to log in", "How to add a product in the cart", and "How to edit a product in the cart".
To view the first part, click this link - http://invotide.com/client/knowledgebase.php?action=displayarticle&id=389

Today, we'll extend our journey and see a couple more examples which we'll need to create a complete order in Invotide using the API. We'll start from where we left the last part, so we assume that you've created the common.php, login.php, add_product.php and edit_product.phpfiles already.

To start with, we'll first add the shipping address.

Create a file add_shipping_address.php with the following contents.

We're passing all the required fields for the shipping address in the $fields array. You should see a "Success: Shipping address has been set!" message in case of success!

Create a file add_shipping_method.php with the following contents.

To set the shipping method of the order, we should know which shipping methods are available in the first place. Thus, we've retrieved the list of shipping methods in the first CURL call in above example. I assume that you've enabled the "Free Shipping" method in the back-end, as we're going to use it as our shipping method.

In the next CURL call, we've passed the shipping_method code as an argument which is required to set the shipping method.

Finally, you should see "Success: Shipping method has been set!" method as a success. One important thing to note here is that the order in which you set "Shipping Address" and "Shipping Method" is important. First, you'll need to set the "Shipping Address" and after that you should make a call to set "Shipping Method".

Create a file add_payment_address.php with the following contents.

This is almost identical to the "Shipping Address" example, except that it'll set the payment address of the order. You should see "Success: Payment address has been set!" in the case of success.

Create a file add_payment_method.php with the following contents.

Again, pretty similar stuff as we did for the "Shipping Method" example. In the first CURL call, we've retrieved the list of payment methods, and fetched the code of the "Cash On Delivery" payment method. In the next CURL call, we've passed the payment_method code as an argument which is required to set the payment method.

As a result, you should see "Success: Payment method has been set!"

Now, let's go ahead and set up the customer data. Create a file add_customer_data.php with the following contents.

Nothing extraordinary—we've just passed the required customer fields to the API! The message "You have successfully modified customers" should give you the confirmation of success.

So far, we've set up everything nicely for our order. The only remaining thing to complete our order is to make an API call to create an order, and that's the recipe of our next section!

Create a file add_order.php with the following contents.

Although it's pretty simple code to create a new order, the important thing to note here is that you need to pass the "Shipping Method" as an argument. Yes, it's a bit weird as we've already set up the shipping method in the earlier example, but that's how it works at the moment.

So, that's the complete process to create an order in Invotide using REST APIs. There are a few other APIs as well to set up coupons, rewards and vouchers, but for brevity we will leave them for you to explore! To view the full documentation of Invotide REST APIs, click the link below.

http://invotide.com/client/knowledgebase.php?action=displayarticle&id=391

In this series, we've discussed the REST APIs in Invotide. We took a ride through the PHP cURL examples to see the usage of the APIs. We hope that it helps you to integrate third-party systems with Invotide. If you experience any issues with APi, feel free to contact Invotide Support team.

Was this answer helpful?

 Print this Article

Also Read

API Documentation

Before using Invotide API you should enable it previously, via admin part of your site. Go to...

Explore REST APIs In Invotide Part 1

Invotide API system allows third party applications to talk to your Invotide store for better...

Language: