bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET
MIT License
122 stars 42 forks source link

Aspnet Core Web API #38

Closed mrccarvalho closed 1 year ago

mrccarvalho commented 1 year ago

Hi @bgmulinari,

In first place, great Job!

I developed a web Api Core to integrate an external web application with SAP B1 to create Orders and more... I used DI API, it works, but it i think is not the best approach to do that.

I developed authentication and authorization with JWT with identity core to authenticate to my web api.

After reading your article, it seems that your solution is too much better than mine, and save a lot of work, very clean ...

In my case, i can make posts, gets.

My endpoints: base_url/api/v1/Login base_url/api/v1/SalesOrder

My doubt is how too adapt and use your solution.

For example, I need to have an endpoint base_url/api/v1/Login, and instead of using my authentication logic, i can call LoginAsync inside my Authentication Controller ?

thanks! cheers Roger

bgmulinari commented 1 year ago

Hi, @mrccarvalho.

In the article I provide an example showing how you can integrate B1SLayer in an ASP.NET Core application using dependency injection to mange your SLConnection instance.

In regards to your authentication logic, I'm not sure I follow what you intend to do. As stated in the article, B1SLayer will authenticate automatically with the credentials provided in your SLConnection instance, so you don't need to call the b1s/v1/Login endpoint since B1SLayer will do that for you.

mrccarvalho commented 1 year ago

Hi ! Thanks for your time.

Sorry, i wasn't clear and i made some confusion. when i mentioned base_url/api/v1/Login, its my end-point to authorize and protect my Web Api Core.

Of course you are right. Sap b1 connection is done by B1SLayer.

Thanks again.

bgmulinari commented 1 year ago

No problem, @mrccarvalho.

In regards to how you are going to manage the authentication on your API, it's entirely up to you (JWT is fine) and it shouldn't affect B1SLayer.

Let me know if you still have any doubts.

mrccarvalho commented 1 year ago

Hi @bgmulinari !

I didn't want to take too much of your time, but I'm fighting with an issue that i cant figure out.

I Can Post BusinessPartners, Get Orders, GetOrder By Id...

but cannot Post Orders Or Invoices.


Error details:
ex = {"Critical Exception in CBusinessObject::Create!
InnerException = {"Call failed with status code 400 (Bad Request): POST https://NDB@pthanab1:50000/b1s/v1/Orders"}
StackTrace = "   at Flurl.Http.FlurlRequest.<HandleExceptionAsync>d__35.MoveNext()\r\n   at Flurl.Http.FlurlRequest.<SendAsync>d__29.MoveNext()\r\n   at Flurl.Http.FlurlRequest.<SendAsync>d__29.MoveNext()\r\n   at Flurl.Http.ResponseExtensions.<ReceiveString>d__3.MoveNe...

thanks in advance.

jmartins-sh commented 1 year ago

Could you post a code sample of your request @mrccarvalho? And the definitions of all related classes and objects.

The error happens when you try to create your Sales Order using an external client, like Postman or Curl? How about the SAP Client itself, work fine using it to create a new Sales Order?

Looks like that something is wrong on the SAP side, not in B1SLayer.

mrccarvalho commented 1 year ago

Hi @joaoantoniomartinsfilho. Thanks in advance!

About the Client SAP itself, i can create Orders with no problem Even with DI API.

So about using external client: I tested it using Postman, Swagger, Soap UI and the error is exactly the same.

I can do Order Gets, Customer Posts, for example, and it creates successfully.

But when creating Sales Order or Invoices the error is:

imagem

Thank you so much for your help!

bgmulinari commented 1 year ago

Hi, @mrccarvalho. The 400 Bad Request status code usually happens when there's something wrong on the client side, that is, your request. However, I tested an order creation with the same fields you provided in your example and the document was created sucessfully.

The fact that the error also happens in Postman indicates that this issue has nothing to do with B1SLayer. My guess would be something wrong with your specifc environment or Service Layer installation.

In any case, the people over the SAP Community should be able to assist you on this, so I encourage you to ask a question there.

I'm closing this specific issue, but if you encounter any problems or doubts regarding B1SLayer in the future, feel free to open another one.

mrccarvalho commented 1 year ago

Hi, @bgmulinari and @joaoantoniomartinsfilho.

Thank you very much for your help. You are totally right. B1Slayer works great.

There was a problem with the SAP database. I tried with another SAP database and it works!

honestly, I appreciate B1Slayer's work. Congratulations!

I wish I could contribute in any way because of your support!

Thanks again. Cheers.

Márcio

thiagobarrosrj commented 6 months ago

Olá @bgmulinari, primeiro agradecer pelo excelente trabalho com essa lib.

Aproveitando esse assunto do login.

Eu estou criando uma API com AspNet Core Web API e posso receber múltiplos logins. Existe alguma forma de eu gerenciar estes múltiplos logins com o B1SLayer para que a criação de pedidos, por exemplo, seja realizado para cada usuário correspondente?

Pois eu percebi que quando eu faço o primeiro login, essa conexão fica salva e não acata os próximos logins.

bgmulinari commented 6 months ago

@thiagobarrosrj, você precisa de várias instâncias para trabalhar com múltiplos logins. Veja mais detalhes na issue #51.

thiagobarrosrj commented 6 months ago

@thiagobarrosrj, você precisa de várias instâncias para trabalhar com múltiplos logins. Veja mais detalhes na issue #51.

@bgmulinari, ótimo. Exatamente isso que eu preciso. Vou tentar implementar. Obrigado.