on 2024 Aug 10 5:49 AM
Hello community, I hope you can help me, we are developing a console application with C#.
When we test via POSTMAN, everything works and updates the records, but when we do it via C# it doesn't work.
We share with you 2 approaches with which we test in C3 and both approaches fail.
Our code :
from this repo
https://github.com/adrian-scan4sap/code-queries-sl/blob/main/code-queries-sl/Program.cs
public static async Task TestPatch(){
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
string baseUrl = "https://1.10.80.20:40000/b1s/v1/";
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
string businessPartnerUrl = $"{baseUrl}/BusinessPartners('USA140FGH82500')";
// Create a JSON payload for the new Business Partner
JObject businessPartnerData = new JObject
{
{ "CardCode", "USA140FGH82500" }, // Provide a unique Business Partner code
{
"ContactEmployees", new JArray
{
new JObject
{
{ "Name", "Example Name 1..." },
}
}
}
};
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(businessPartnerUrl);
request.Method = "PATCH";
request.ContentType = "application/json";
request.Accept = "application/json";
request.Headers.Add("Cookie", $"B1SESSION={'7545-8455-SA-TOKEN'}");
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(businessPartnerData.ToString());
streamWriter.Flush();
streamWriter.Close();
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.NoContent)
{
Console.WriteLine("Business Partner Contact updated successfully.");
}
else
{
Console.WriteLine("Failed to update Business Partner Contact. Status code: " + response.StatusCode);
}
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while updating the Business Partner Contact: " + ex.Message);
}
Result : Error 500 !
please, can someone give us some help, some link, some repository, some code?
Hello,
Here are some suspictions.
1. Make sure the Service layer port is 40000. the port 40000 is typically used for SLD service. the default Service Layer port is 50000.
string baseUrl = "https://1.10.80.20:40000/b1s/v1/";
2. The variable for B1 session id "7545-8455-SA-TOKEN" looks strange. make sure if you used the correct variable to hold the the session id through login.
request.Headers.Add("Cookie", $"B1SESSION={'7545-8455-SA-TOKEN'}");
3. As a general tip, it would be helpful to test with a simpler JSON format, for example, GET BP to isolate the issue from JSON format.
Regards
EunSeok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
66 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.