Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestEndpoint : conversion error when the parameter type is defined to Int when using POST method #106

Closed
apetitjean opened this issue Apr 25, 2018 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@apetitjean
Copy link

Why do I have an error when I force the type of my parameter to Int?
If I remove the type declaration (just "[int]" in the param block) it works without any error.
Problem is : I need to distinguish a string from an int passed to my Rest API. Is that possible?

Here's my server code:

$Endpoint00 = New-UDEndpoint -Url "/test" -Method "POST" -Endpoint {
    param( [Int]$value )

    $value
} 

Client call:

PS C:\> Invoke-RestMethod -Uri 'http://localhost:3000/api/test' -Method POST -Body {value=2}

error
-----
@{message=Cannot process argument transformation on parameter 'value'. Cannot convert the "2" value of type "Microsoft.Extensions.Primitives.StringValues" t...

Error log :

18:02:11 ExecutionService Error executing endpoint script. Cannot process argument transformation on parameter 'value'. Cannot convert the "2" value of type "Microsoft.Extensions.Primitives.StringValues" to type "System.Int32".
18:02:11 ComponentController {"Error":{"message":"Cannot process argument transformation on parameter 'value'. Cannot convert the \"2\" value of type \"Microsoft.Extensions.Primitives.StringValues\" to type \"System.Int32\".","location":nul
l,"type":"error","id":null,"refreshInterval":0,"autoRefresh":false,"hasCallback":false}}
@apetitjean
Copy link
Author

If I remove the type declaration it works as expected.
As I always oblige myself to declare types when I know them, is it bad to do that in the context of a Rest API?

Here is what I get without declaring any type in the param block of my Endpoint:

PS C:\> $i = Invoke-RestMethod -Uri 'http://localhost:3000/api/test' -Method POST -Body {value=2}
PS C:\> $i.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Int64                                    System.ValueType


PS C:\> $i = Invoke-RestMethod -Uri 'http://localhost:3000/api/test' -Method POST -Body {value='2'}
PS C:\> $i.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

@adamdriscoll
Copy link
Member

Interesting! I haven't run into this before. It seems like it should be fixed though. I don't see why you could specify typed values.

@adamdriscoll adamdriscoll added the bug Something isn't working label Apr 25, 2018
@apetitjean
Copy link
Author

apetitjean commented Apr 25, 2018 via email

@adamdriscoll
Copy link
Member

@apetitjean That was a typo: couldn't!

I think it should work the way you suggest.

@adamdriscoll adamdriscoll added this to the 1.6.2 milestone Jun 6, 2018
@adamdriscoll
Copy link
Member

Fixed in 1.6.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants