Help forum

Passing json in the body of a request

  • David Bain

    2 years ago

    I'm trying to replicate the following example with toddle. (BTW... this is how fastgen requests an auth token)
    curl --location 'https://my-project.fastgenapp.com/auth/signin' \
    --header 'rid: thirdpartyemailpassword' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "formFields": [
    {
    "id": "email",
    "value": "timon@fastgen.com"
    }, {
    "id": "password",
    "value": "<mySecretPassword1>"
    }
    ]
    }'

    for my initial tests I'm hardcoding.
    When I attempt to add the contents of data-raw as a value in the body
    I get the error: "json: cannot unmarshal string into Go value of type map[string]interface {}\n"
    1259838480016478268-image.png
  • Andreas Møller

    2 years ago

    toddle automatically json encodes the body, so you your case it will be encoded twice
  • David Bain

    2 years ago

    I ended up using a formula:
    1. select formula
    2. json parse the string
    1259842330014515200-image.png
  • Tod

    2 years ago

    Great energy @David Bain! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • David Bain

    2 years ago

    Would appreciate further guidance on this... I'm not clear on how to do it otherwise... especially since I'll need to dynamically load the email and password from the form.
    I'm thinking to expand the formula to support the dynamic loading of the email and password.
  • Andreas Møller

    2 years ago

    Can you show me the formula for the body
  • David Bain

    2 years ago

    I pasted this into the parse json
    { "formFields": [ { "id": "email", "value": "me@example.com" }, { "id": "password", "value": "HABLplDeFgY5sA" } ] }
  • Andreas Møller

    2 years ago

    Ah. So I assume you want the email and password to be dynamic?
  • David Bain

    2 years ago

    that's the plan... and my next step
  • Andreas Møller

    2 years ago

  • David Bain

    2 years ago

    Thanks @Andreas Møller ... will check it out (my fault for skipping the 7 days of toddle videos 🤕 )
    😎1
  • David Bain

    2 years ago

    @ my future self... important stuff from the video:

    some key ideas:
    1. bind input form fields to variables: https://youtu.be/NItmmOhjXbA?si=9MXS1qZPCn7F7VOR&t=1058
    2. use a formula to dynamically customise the request: https://youtu.be/NItmmOhjXbA?si=ObOO4Se_VSsB76vS&t=2194
    3. trigger based on form submit: https://youtu.be/NItmmOhjXbA?si=pKLTCFDK8kahguxT&t=2256
    4. present errors to the user: https://youtu.be/NItmmOhjXbA?si=AH7-4xdSjioqQjUk&t=2474
    5. store auth token in a cookie: https://youtu.be/NItmmOhjXbA?si=wihVi46cOMG2r0Y1&t=2730
  • Andreas Møller

    2 years ago

    🙂
  • David Bain

    2 years ago

    @Andreas Møller I know you have to choose your battles when building out a product experience. So you can take this thought or leave it.
    It's a lot of work to go through the videos and do it, but it would be really valuable to add annotated timestamps on the videos.
  • Andreas Møller

    2 years ago

    Indeed! We have them
    On most of our vids 🙂 not sure why this one is lacking
  • David Bain

    2 years ago

    added a comment on the video you shared:
    very specific for authentication..., so it isn't all the annotations you'll need, if useful for you... feel free to steal them please 🙂
    1259851816758280245-image.png
    🔥3
  • Lucas G

    2 years ago

    That will help many people 🙏
  • Andreas Møller

    2 years ago

    Thank you!
  • Andreas Møller

    2 years ago

    Just just updated the video description!
    🔥1
  • David Bain

    2 years ago

    @Andreas Møller ... thanks for this...
    just a note.... Youtube only shows timestamps in the interface if there is a 00:00 - xxxxxxxxx timestamp included in the description
    example:
    00:00 - Introduction
    01:00 - Next thing
  • Andreas Møller

    2 years ago

    It is now
  • Andreas Møller

    2 years ago

    Not sure why youtube is not picking them up.
  • @Andreas Møller
    It is now

    David Bain

    2 years ago

    Typically adding a zero entry (00:00:00 - Intro) does the trick
    👇🏾
    00:00:00 - Introduction 👈🏾
    00:17:38 - bind form fields to variables
    00:36:34 - use a formula to dynamically customise the request
    00:37:36 - trigger based on form submit
    00:41:14 - present errors to the user
    00:45:30 - store auth token as session cookie and go to url
    00:53:07 - add toddle chrome plugin (to support cookie tracking in the editor)
    00:54:36 - create a /login page
    01:00:00 - use securely stored access token (authorization header)