here is the json schema for the code
namespace VeeqoIntegration.Models
{
}
public class Rootobject
{
public Product product { get; set; }
}
public class Product
{
public string title { get; set; }
public string description { get; set; }
public string estimated_delivery { get; set; }
public string notes { get; set; }
public string product_brand_id { get; set; }
public List< Product_Variants_Attributes> product_variants_attributes { get; set; }
public List<Images_Attributes> images_attributes { get; set; }
}
public class Product_Variants_Attributes
{
public string title { get; set; }
public string sku_code { get; set; }
public decimal cost_price { get; set; }
public decimal price { get; set; }
public int min_reorder_level { get; set; }
public int quantity_to_reorder{ get; set; }
public int tax_rate { get; set; }
public string upc_code { get; set; }
public string model_number { get; set; }
public float weight_grams { get; set; }
public string weight_unit { get; set; }
//public string Brand{ get; set; }
}
public class Images_Attributes
{
public string src { get; set; }
public int display_position { get; set; }
}
here is the code for your reference and if there are any errors let me know by today
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Configuration;
using System.Web;
using Veeqo_Integration;
namespace VeeqoIntegration
{
class Program
{
static void Main(string args)
{
Console.WriteLine(“Welcome to Veeqo integration”);
ExportData();
ExportProducts();
// ExportProducts_CostPrice();
Console.WriteLine("Integration Completed");
Console.ReadLine();
}
static async Task ExportData()
{
modGeneral obj = new modGeneral();
Console.WriteLine("Exporting Products...");
await ExportProducts();
obj.captureErrorLog("Integration Completed ", "");
Environment.Exit(0);
Console.WriteLine("Successfully Updated...");
Console.ReadLine();
Environment.Exit(0);
}
static async Task ExportProducts()
{
modGeneral obj = new modGeneral();
try
{
var client = new HttpClient();
var APIKEY = ConfigurationManager.AppSettings.Get("APIkEY");
DateTime ProductLastUpdatedAt = obj.GetLastUpdated("Products");
obj.captureErrorLog("Products Exporting", "");
var uri = "https://api.veeqo.com/products";
DataTable dtProducts = obj.LoadDataTable("Select * from View_ExportProductstoAPI where isnull(APIID,'')='' and Modifieddatetime>= '" + obj.FormatDatetime(ProductLastUpdatedAt) + "' Order by Modifieddatetime ");
int i = 0;
if (dtProducts != null && dtProducts.Rows.Count > 0)
{
Rootobject ProductList = new Rootobject();
obj.captureErrorLog("Products records found", Convert.ToString(dtProducts.Rows.Count));
int k = dtProducts.Rows.Count;
foreach (DataRow row in dtProducts.Rows)
{
k--;
i++;
Rootobject ProductList1 = new Rootobject();
Product objPro = new Product();
Product_Variants_Attributes objVar = new Product_Variants_Attributes();
Images_Attributes objimg = new Images_Attributes();
List<Product_Variants_Attributes> Varlist = new List<Product_Variants_Attributes>();
List<Images_Attributes> ImgList = new List<Images_Attributes>();
try
{
objPro.title = obj.AlwaysAString(row["Product_Description"].ToString());
objPro.description = obj.AlwaysAString(row["Product_Description"].ToString());
objPro.notes = obj.AlwaysAString(row["PopUpNotes"].ToString());
// objPro.product_brand_id = obj.AlwaysAString(row["MainProductCode"].ToString());
objVar.title = obj.AlwaysAString(row["Product_Description"].ToString());
objVar.sku_code = obj.AlwaysAString(row["Central_Product_Code"].ToString());
objVar.cost_price = Convert.ToDecimal(row["Cost_Price"].ToString());
objVar.price = Convert.ToDecimal(row["SellingPrice"].ToString());
objVar.min_reorder_level = Convert.ToInt32(row["ReOrder_Level"]); ;
objVar.quantity_to_reorder = Convert.ToInt32(row["Stock_Max_Level"]);
objVar.tax_rate = Convert.ToInt32(row["Vat_Percentage"].ToString());
objVar.upc_code = obj.AlwaysAString(row["Br_Code"].ToString());
//objVar.Brand = obj.AlwaysAString(row["Supplier_Description"].ToString());
objVar.product_brand_id = obj.AlwaysAString(row["MainProductCode"].ToString());
Varlist.Add(objVar);
objPro.product_variants_attributes = Varlist;
DataTable DtImages;
DtImages = obj.LoadDataTable("Select Imageurl from ProductImages where centralProductCode='" + obj.AlwaysAString(row["Central_Product_Code"].ToString()) + "'");
if (DtImages.Rows.Count > 0)
{
int n = 0;
foreach (DataRow rowimage in DtImages.Rows)
{
n = n + 1;
objimg.src = rowimage["Imageurl"].ToString();
objimg.display_position = n;
ImgList.Add(objimg);
}
}
objPro.images_attributes = ImgList;
ProductList1.product = objPro;
using (var clientSS = new HttpClient())
{
string strProductsJSON = JsonConvert.SerializeObject(ProductList1);
HttpContent obj1 = new StringContent(strProductsJSON, Encoding.UTF8, "application/json");
try
{
clientSS.DefaultRequestHeaders.Accept.Clear();
clientSS.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
clientSS.DefaultRequestHeaders.Add("x-api-key", APIKEY);
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
clientSS.Timeout = TimeSpan.FromMinutes(10);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | (SecurityProtocolType)3072;
var responce1 = clientSS.PostAsync(uri, obj1).Result;
var result1 = responce1.Content.ReadAsStringAsync().Result;
if (responce1.IsSuccessStatusCode)
{
{
obj.captureErrorLog("Product Added --", row["Central_Product_Code"].ToString());
// var result2 = responce1.Content.ReadAsStringAsync().Result;
// Object lstCreditNotes = Newtonsoft.Json.JsonConvert.DeserializeObject<Object>(result2);
dynamic get_ProductResponce = JsonConvert.DeserializeObject<Object>(result1);
double ProductId = 0;
double Product_VarientId = 0;
ProductId = get_ProductResponce.product.id;
if (ProductId != 0)
{
obj.ExecuteSQL("Update Product_Master set APIID=" + ProductId + ",VarientId=" + Product_VarientId + " where Central_Product_Code='" + obj.AlwaysAString(row["Central_Product_Code"].ToString()) + "' ");
//obj.ExecuteSQL("Update ShopifyAPILog set LastUpdatedAt='" + obj.AlwaysAString(row["ModifiedDateTime"].ToString()) + "' where Module='Products' ");
// obj.ExecuteSQL("Update ShopifyAPILog set LastUpdatedAt='" + obj.AlwaysAString(row["ModifiedDateTime"].ToString()) + "' where Module='Product_Updates' ");
}
}
}
else
{
string error = responce1.ReasonPhrase.ToString();
obj.captureErrorLog("Error while adding product -- " + error, strProductsJSON);
}
}
catch (Exception e)
{
obj.captureErrorLog("Error While adding Product" + obj.AlwaysAString(row["Central_Product_Code"].ToString()), e.Message);
}
}
}
catch (Exception e)
{
obj.captureErrorLog("Error While adding Product" + obj.AlwaysAString(row["Central_Product_Code"].ToString()), e.Message);
}
}
}
}
catch (Exception e)
{
obj.captureErrorLog("Error While adding Product", e.Message);
}
}
}
}