HomeHome Product Discus... Product Discus...RazorCartRazorCartCreating/updating products using the Rest APICreating/updating products using the Rest API
Previous
 
Next
New Post
9/28/2017 1:48 PM
 
How do I use the REST API to programmatically create and update products? I don't understand what should I set in 'Application' and 'Callback' URL. Should I set both as the store's (the site's) URL?

Our RESTful API programming follows the standard "OAuth 2.0 Authorization Framework":
  • Implicit Grant: https://tools.ietf.org/html/rfc6749#section-4.2
    • It's used when you have another website that will show/update the information on your DNN/RazorCart site, in this case the user will be redirected to the DNN login page and redirect back to the other website with an access token can be used after that to retrieve/modify via HTTP request methods
    • So this only works via the web browser and require user action to login using the DNN login page.
  • Resource Owner Password Credentials Grant https://tools.ietf.org/html/rfc6749#section-4.3
    • It can be used on the same site or from anywhere (web browser, mobile app, another API service, server-side applications) any framework that can make HTTP 1.1 request
    • In C# you just need to use the HttpWebRequest class to get an access token, then use the token to make any request type like (GET (retrieve data), POST (create), PUT (update), DELETE (delete record))
C# code to obtain authentication access token
var storURL = "https://domain.com/DesktopModules/RazorCart/Services/v1/Authorize"; 
var request = (HttpWebRequest)WebRequest.Create(storURL); 

var postData = "grant_type=password&username=host&password=password&scope=orders%20edit"; 
var data = Encoding.ASCII.GetBytes(postData); 

request.Method = "POST"; 
request.ContentType = "application/x-www-form-urlencoded"; 
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(ClientID + ":"); 

using (var stream = request.GetRequestStream()) 
{ 
     stream.Write(data, 0, data.Length); 
} 

var response = (HttpWebResponse)request.GetResponse(); 
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
The same above code can be re-used for the other HTTP requests depends of the desire endpoint the url/params will change
 
Currently there's no CreateProductImage endpoint, the REST API does not handle file uploads.  To upload images you need to ftp or use the dnn file manager.
 
Previous
 
Next
HomeHome Product Discus... Product Discus...RazorCartRazorCartCreating/updating products using the Rest APICreating/updating products using the Rest API