bgmulinari / B1SLayer

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

Any way to bypass URL Encoding? #45

Closed grantsanders closed 11 months ago

grantsanders commented 11 months ago

I'm trying to access the SQLQueries endpoint and pass in a parameter, which requires a url that looks like this:

GET /b1s/v2/SQLQueries('')/List?

I'm having problems calling this with B1Slayer though- I tracked the service layer logs and it looks like the issue is related to the URL encoding, my assumption is this comes from Flurl?

Given this sample code:

var attachmentInfo = await _serviceLayer.Request("SQLQueries('GetAttachmentCode')/List?fileName='test'").GetAsync();

The actual request that makes it to the service layer looks like this:

GET /b1s/v2/SQLQueries('GetAttachmentCode')/List%3FfileName='test'

The issue here seems to be at the '/List?' section of the URL- either B1Slayer or Flurl seems to be encoding the question mark, which the service layer doesn't seem to agree with. When I test the request in Postman, no issue- when I try it from B1Slayer (And from Postman with the ? pre-encoded to %3F) I get this error from SAP:

"error": { "code": "-1008", "message": "Command Not Found" }

Is there any way to bypass the URL encoding that the library is doing to the request string? Appreciate your time and your library!

bgmulinari commented 11 months ago

Hi, @grantsanders.

For this case in particular, you should use the SetQueryParam extension method to set your query parameter. This should avoid the issue with URL encoding.

var attachmentInfo = await serviceLayer
    .Request("SQLQueries('GetAttachmentCode')/List")
    .SetQueryParam("fileName", "'test'")
    .GetAsync();

Let me know if this works.

grantsanders commented 11 months ago

Works perfectly. Thank you!