Ashok

Ashok

  • NA
  • 507
  • 76.3k

I am trying to POST data to API

Apr 16 2020 10:16 AM
Hi All,
 
priority : High
 
Following is the code trying to POST data from C# code following is the response.please help me out on this.Thank You.
 
my response json
---------------
{
"type": "https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1",
"title": "Error while accessing resource: Please enter value(s) for: Company Name",
"status": 400,
"o:errorCode": "USER_ERROR"
}
 
 
String header = "Authorization: OAuth ";
header += "oauth_signature=\"" + signature + "\",";
header += "oauth_version=\"1.0\",";
header += "oauth_nonce=\"" + nonce + "\",";
header += "oauth_signature_method=\"HMAC-SHA1\",";
header += "oauth_consumer_key=\"" + ckey + "\",";
header += "oauth_token=\"" + tkey + "\",";
header += "oauth_timestamp=\"" + timestamp + "\",";
header += "realm=\"TSTDRV1122337\"";
HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create("https://TSTDRV1122337.suitetalk.api.netsuite.com/services/rest/record/v1/vendor");
Postrequest.ContentType = "application/json";
Postrequest.Method = "POST";
Postrequest.Headers.Add(header);
postvendordetails objvendor = new postvendordetails();
objvendor.vendorprimaryinformation = new postvendordetails.PrimaryInformation();
objvendor.vendorprimaryinformation.Type = false;
objvendor.vendorprimaryinformation.CompanyName = "Testing";
objvendor.vendorprimaryinformation.Category = "2";
objvendor.vendorprimaryinformation.Comments = "vendor creation";
objvendor.vendorprimaryinformation.WebAddress = "https://google.com";
objvendor.vendorprimaryinformation.Email = "[email protected]";
objvendor.vendorprimaryinformation.AltPhone = "999-999-9999";
objvendor.vendorprimaryinformation.Phone = "2504920100";
objvendor.vendorprimaryinformation.Fax = "2504920100";
objvendor.vendorprimaryinformation.subsidiary = "1";
string postdata = JsonConvert.SerializeObject(objvendor);
using (var streamWriter = new StreamWriter(Postrequest.GetRequestStream()))
{
streamWriter.Write(postdata);
streamWriter.Flush();
streamWriter.Close();
}
HttpWebResponse httpResponse = null;
try
{
httpResponse = (HttpWebResponse)Postrequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
catch (JsonException ex) // To capture JSON exceptions
{
string message = ex.Message.ToString();
}
postvendordetails.cs
--------------------
public class postvendordetails
{
public PrimaryInformation vendorprimaryinformation { get; set; }
public class PrimaryInformation
{
public string subsidiary { get; set; }
public Boolean Type { get; set; }
public string CompanyName { get; set; }
public string WebAddress { get; set; }
public string Category { get; set; }
public string Comments { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string AltPhone { get; set; }
public string Fax { get; set; }
}
}
my request json
---------------
{
"vendorprimaryinformation": {
"isperson": false,
"companyName": "Testing",
"category": "2",
"comments": "vendor creation",
"url": "https://google.com",
"email": "[email protected]",
"altphone": "999-999-9999",
"phone": "2504920100",
"fax": "2504920100",
"subsidiary": "1"
}
}

Answers (5)