In just a few minutes we'll be shipping BV Commerce 6.0.40. This update brings some new features (like order editing) and includes a new REST based API. For those who don't know, REST is a way to let machines communicate to each other using standard HTTP protocols. When you type in a URL into your web browser you are making an HTTP GET request and asking a web server to "get" a web page for you. When you submit a form on a web site you're sending an HTTP POST request and posting some form data to a web server.
REST based APIs are simple by nature. They rely on the convention that each "resource" should have a single URL. For example, /api/v1/rest/products/abc123 would represent product ABC123. If I made an HTTP DELETE request to that address the server would delete that product if I have the correct permissions to do so.
Fortunately, you don't have to learn about HTTP methods and REST conventions to work with the new API in BV Commerce 6. We've created a simple class library that makes your life easier. Here's a quick tutorial:
1) Create a new project in Visual Studio
2) Add a reference to the BVSoftware.CommerceDTO class library
3) Make sure you have an API key created under Options->Api in the Admin side of your store
4) Here's the sample code to create a product:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BVSoftware.CommerceDTO.v1;
using BVSoftware.CommerceDTO.v1.Client;
using BVSoftware.CommerceDTO.v1.Catalog;
namespace SuperSimpleApiSample
{
class Program
{
static void Main(string[] args)
{
// Create the proxy to your remote storeApi
remoteServer = new Api("http://www.mystore.com", "my api key");
// Create a local product object
ProductDTO p = new ProductDTO();
p.Sku = "ABC123";
p.ProductName = "My Sample Product";
p.SitePrice = 19.95m;
// Call the create function
// - Note, we're passing null instead of uploading an image for this sample
ApiResponse response = remoteServer.ProductsCreate(p, null);
// Output the newly created BVIN value for the product
Console.WriteLine("The bvin of the created product is " + response.Content.Bvin);
}
}
}