BUSINESS PARTNER USANDO SERVICE LAYER

Code with Edd

CREAR BUSINESS PARTNER (SOCIO DE NEGOCIO) UTILIZANDO SERVICE LAYER (API) DE SAP BUSINESS ONE.

El siguiente fragmento de código es para crear un socio de negocio utilizando la api de SAP Business One Service Layer.

El método recibe dos parametros, el objecto con los datos del nuevo socio de negocio, y el id de la sesión activa.

[HttpPost("{sessionId}")]
[ActionName("addbp")]
public async Task<ActionResult> BusinessPartners([FromBody] BusinessPartners? body, string sessionId)
{
    try
    {
        object? result;

        var json = Newtonsoft.Json.JsonConvert.SerializeObject(body);
        var contenido = new StringContent(json, Encoding.UTF8);

        httpClient.DefaultRequestHeaders.Add("Cookie", String.Format("B1SESSION={0}", sessionId));
        HttpResponseMessage response = await httpClient.PostAsync("b1s/v1/BusinessPartners", contenido);

        if (response.IsSuccessStatusCode)
        {
            result = await response.Content.ReadFromJsonAsync<object>();
        }
        else
        {
            result = await response.Content.ReadFromJsonAsync<object>();

            if (response.StatusCode == HttpStatusCode.BadRequest) { return BadRequest(result); }
            if (response.StatusCode == HttpStatusCode.NotFound) { return NotFound(Array.Empty<string>()); }
            if (response.StatusCode == HttpStatusCode.Unauthorized) { return StatusCode(401, result); }
            if (response.StatusCode == HttpStatusCode.InternalServerError) { return StatusCode(500, result); }
        }

        return Ok(JsonSerializer.Serialize(result));
    }
    catch (Exception ex)
    {
        return StatusCode(500, new ResponseError { code = 500, message = ex.Message, error = Array.Empty<string>() });
    }
}

Ejemplo del objeto del socio de negocio.

public class BusinessPartners
{
    public int Series { get; set; } = 0;
    public string CardName { get; set; } = String.Empty;
    public string CardType { get; set; } = String.Empty;
    public string FederalTaxID { get; set; } = String.Empty;
    public string Phone1 { get; set; } = String.Empty;
}

Referencia: Service Layer API Reference.

Create an instance of 'BusinessPartners' with the given payload of type 'BusinessPartner' in JSON format.

Example
POST https://localhost:50000/b1s/v1/BusinessPartners

{
    "CardCode": "c001",
    "CardName": "c001",
    "CardType": "C"
}
BUSINESS PARTNER USANDO SERVICE LAYER
Web | + posts

Full Stack Web Developer && SDK SAPB1 Developer.

Melómano, Gamer (Xbox), Comprador compulsivo de Amazon y Posiblemente con TDAH.

Scroll hacia arriba