PricingBlog

Passing json in the body of a request

  • pigeonflight-1259838479890780232

    David Bain

    1 year 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
  • andreasmoller-1259841771471372370

    Andreas Møller

    1 year ago

    toddle automatically json encodes the body, so you your case it will be encoded twice
  • pigeonflight-1259842330291212348

    David Bain

    1 year ago

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

    Tod

    1 year ago

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

    David Bain

    1 year 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.
  • andreasmoller-1259842901127598152

    Andreas Møller

    1 year ago

    Can you show me the formula for the body
  • pigeonflight-1259843085802803332

    David Bain

    1 year ago

    I pasted this into the parse json
    { "formFields": [ { "id": "email", "value": "me@example.com" }, { "id": "password", "value": "HABLplDeFgY5sA" } ] }
  • andreasmoller-1259843107395080272

    Andreas Møller

    1 year ago

    Ah. So I assume you want the email and password to be dynamic?
  • pigeonflight-1259843161270911090

    David Bain

    1 year ago

    that's the plan... and my next step
  • andreasmoller-1259843351851569213

    Andreas Møller

    1 year ago

  • pigeonflight-1259843561986330624

    David Bain

    1 year ago

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

    David Bain

    1 year 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
  • andreasmoller-1259844392265453679

    Andreas Møller

    1 year ago

    🙂
  • pigeonflight-1259848173896073246

    David Bain

    1 year 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.
  • andreasmoller-1259849377015533689

    Andreas Møller

    1 year ago

    Indeed! We have them
    On most of our vids 🙂 not sure why this one is lacking
  • pigeonflight-1259851817249017966

    David Bain

    1 year 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
  • lucasg-1259854239744786537

    Lucas G

    1 year ago

    That will help many people 🙏
  • andreasmoller-1259859136112365609

    Andreas Møller

    1 year ago

    Thank you!
  • andreasmoller-1259859934192074752

    Andreas Møller

    1 year ago

    Just just updated the video description!
    🔥1
  • pigeonflight-1259861130084614194

    David Bain

    1 year 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
  • andreasmoller-1259866100389384295

    Andreas Møller

    1 year ago

    It is now
  • andreasmoller-1259866642058313728

    Andreas Møller

    1 year ago

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

    David Bain

    1 year 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)