Method PostCommodities

Summary

Get list of Commodities

Remarks

Returns the list of commodities with no sub-commodities included

Input Parameters

NameTypeLengthDescription
companyNumber numeric 3 Customer number
rows numeric 4 Number of rows to return
pageNumber numeric 5 Page number. Used with rows for paging of results

Example

POST http://localhost/FusionServices/v3/Naviline/ProductInventory/Commodities

Return Values

NameDescription
ErrorCode 0000=Success
ErrorMessage Error message describing any error that occurred
CommodityCode Commodity Code value
SubCommodityCode Sub-Commodity Code value
CommodityDescription Commodity Code description
ROWS number of rows returned
MOREYN More rows available Y/N

Sample Responses

Sample Code

using System.Net;
using Newtonsoft.Json.Linq;

public void MethodName(parms)
{
   string uri = "http://localhost/FusionServices/v3/Naviline/ProductInventory/Commodities";
   System.Collections.Specialized.NameValueCollection postParms = 
     new System.Collections.Specialized.NameValueCollection(); 
   // Set paramater values
   postParms.Add("companyNumber",System.Web.HttpUtility.UrlEncode("000"));

   WebClient req = new WebClient();
   wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
   wc.Headers.Set("X-APPID", "YOURID");
   wc.Headers.Set("X-APPKEY", "YOURKEY");

   byte[] responseBytes = wc.UploadValues(new Uri(uri), "POST", postParms);
   string stringResult = Encoding.UTF8.GetString(responseBytes); 
   JObject response = JObject.Parse(stringResult);
   string error = response["OutputParms"]["ErrorCode"].ToString();
   if (error == "0000")
   {
        JArray jRows = (JArray)response["Rows"];
        foreach (JObject row in jRows)
        {
             string CommodityCode = row["CommodityCode"].ToString();
             string SubCommodityCode = row["SubCommodityCode"].ToString();
             string CommodityDescription = row["CommodityDescription"].ToString();
             // TODO - YOUR CODE HERE
        }
   }
}

C# Razor MVC Sample Code

using System;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Collections.Specialized;
using FusionServiceHelper.Models;

// NOTE: Use the namespace generated when you add the class, so that it is correct.
namespace FusionRazor.Models
{
   public class PostCommodities
   {
       // Add property for each input param in order to map a field to it
       [RegularExpression("[0-9]{0,3}", ErrorMessage = "Numeric values only. Must be 3 digits or less. ")]
       public string companyNumber{get; set;}

       [RegularExpression("[0-9]{0,4}", ErrorMessage = "Numeric values only. Must be 4 digits or less. ")]
       public string rows{get; set;}

       [RegularExpression("[0-9]{0,5}", ErrorMessage = "Numeric values only. Must be 5 digits or less. ")]
       public string pageNumber{get; set;}

       public PostCommodities()
       {
           //Set any defaults here
       }
   }
}
@* NOTE: Use Add->View to add the View. *@
@* NOTE: Check the 'Create strongly-typed view checkbox, and select the PostCommodities class. *@
@* NOTE: Select Edit as the Scaffold template. *@
@* NOTE: Use the @model line that is generated at the top.  Replace the rest with the lines below.
@model FusionRazor.Models.PostCommodities

@{
   ViewBag.Title = "PostCommodities";
}

<h2>PostCommodities</h2>
@using (Html.BeginForm()) {
   @Html.AntiForgeryToken()
   @Html.ValidationSummary(true)
   <fieldset>
   <legend>PostCommodities</legend>
       <div class="editor-label">
           @Html.LabelFor(model => model.companyNumber)
       </div>
       <div class="editor-field">
           @Html.EditorFor(model => model.companyNumber)
           @Html.ValidationMessageFor(model => model.companyNumber)
       </div>
       <div class="editor-label">
           @Html.LabelFor(model => model.rows)
       </div>
       <div class="editor-field">
           @Html.EditorFor(model => model.rows)
           @Html.ValidationMessageFor(model => model.rows)
       </div>
       <div class="editor-label">
           @Html.LabelFor(model => model.pageNumber)
       </div>
       <div class="editor-field">
           @Html.EditorFor(model => model.pageNumber)
           @Html.ValidationMessageFor(model => model.pageNumber)
       </div>
       <p>
       <input type="submit" value="Submit"/>
       </p>
   </fieldset>

}

@section Scripts {
   @Scripts.Render("~/bundles/jqueryval")
}
using System;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FusionServiceHelper.Models;

// NOTE: Replace 'MyController' with the name of your controller.

// 
// GET: /MyController/PostCommodities
public ActionResult PostCommodities()
{
   // Create a new instance of the model to pick up any default values.
   PostCommodities model =  new PostCommodities();

   // pass model to set to default values
   // NOTE: Change 'MyFolderPath' to the path to the .cshtml file.
   return View("~/Views/MyFolderPath/PostCommodities.cshtml", model);
}

// 
// POST: /MyController/PostCommodities
[HttpPost]
public ActionResult PostCommodities(FormCollection collection)
{
   string url = "v3/Naviline/ProductInventory/Commodities";
   // Get the value from each input field
   NameValueCollection inputParms = new NameValueCollection();
   inputParms.Add("companyNumber", collection["companyNumber"]);
   inputParms.Add("rows", collection["rows"]);
   inputParms.Add("pageNumber", collection["pageNumber"]);

   try
   {
       // Send the request
       FusionServiceRequest request = new FusionServiceRequest();
       FusionServiceResult result = request.Post(url, inputParms);

       return View("Result", result);
   }
   catch(Exception e)
   {
       HandleErrorInfo info = new HandleErrorInfo(e, "MyController", "PostCommodities");
       return View("Error", info);
   }
}