PricingBlog

How do I post application/x-www-form-urlencoded;charset=UTF-8 body parameters?

  • kingsleyh-1272129178732335114

    Kingsley

    1 year ago

    I'm struggling to make an API call to Keycloak direct grant endpoint which is a POST request with some parameters.

    The curl command works fine:
    curl -d 'client_id=some-client' -d 'username=my@email.com' -d 'password=my_password' -d 'grant_type=password' 'https://my-keycloak-server/realms/my-realm/protocol/openid-connect/token'

    but the toddle post complains the grant_type is missing when I make the Body of the request like this:

    client_id=some-client&grant_type=password&username=my@email.com&password=my_password

    I don't know if this is the correct format to be putting in the Body
  • kingsleyh-1272159752583118920

    Kingsley

    1 year ago

    To work around this issue - I've created a proxy backend service which accepts JSON and then calls the Keycloak token endpoint with form params
  • lucasg-1272256289086504960

    Lucas G

    1 year ago

    How are you sending the body?
  • Are you building it out using toddle nodes?
  • It should be JSON already if so
  • If Keyclock needs it stringified then you could use a formula node for that as well
  • kingsleyh-1272280315502661662

    Kingsley

    1 year ago

    keycloak doesn't want Json - only wants old school form-url encoded parameters - usually they would be passed like I put above with key1=value&key2=value etc - If I pass this as a string made by formulas or as a hardcoded string in the body - I always get the same response. I guess toddle is using fetch under the hood and looking at the docs usually you have to make a specific type of javascript object which probably does some work to encode properly or something - so I guess just putting a string in the body isn't going to work
  • lucasg-1272281407569530890

    Lucas G

    1 year ago

    Hmm weird. I'm sure I've tried form encoded before and it worked 🤔 perhaps @Andreas Møller or someone from the toddle team can guide you here