PricingBlog

JSON response to array

  • tcg.store-1283309157960781877

    TCG.Store

    1 year ago

    Has anyone taken a JSON response from auth API and stored the result into an array in toddle? I was trying to see if there are some best practices?
  • max.kayr-1283314237216653313

    Max

    1 year ago

    That depends very much on your data structure. Can you give an example of the data you want to store?
  • tcg.store-1283315579394064418

    TCG.Store

    1 year ago

    {
    "user": {
    "user_id": "1234",
    "email": "abc@toddle.dev",
    "social_id": "",
    "first_name": "Tim",
    "last_name": "Cook",
    "created_at": 1726023688,
    "patreon_access_token": null,
    "is_store": false
    },
    "auth": {
    "access_token": "6789",
    "refresh_token": "",
    "expires_in": 2419200
    }
    }
  • This is an example of what is returned from the API
  • max.kayr-1283316854089318464

    Max

    1 year ago

    I see. Why do you want to store it as an array? An array is a list of items. This seems to be a single record.
  • tcg.store-1283317277105848332

    TCG.Store

    1 year ago

    It's returned from an auth API, and basically want to store the access token and use this to query speciifc users given a few things we want to do
  • tcg.store-1283317703519633468

    TCG.Store

    1 year ago

    This is just an example. It happens to be a single record but either way love to store a specific pieces of an object from an arrary or a single record
  • tcg.store-1283318758538084362

    TCG.Store

    1 year ago

    if that makes sense
  • max.kayr-1283323231075307522

    Max

    1 year ago

    For auth tokens, I would use the set session cookie action from Toddle. This is more secure. Also, variables are reset on refresh or when a component is unmounted.

    For normal data, this depends very much on the data itself. You can store anything from an API in a variable as is. Or you can store only specific parts of it. Depends on your use case
    🔥1
    🙏1
  • tcg.store-1283422714777829387

    TCG.Store

    1 year ago

    Thanks for this suggestion and this makes sense.

    I was trying to see if there were an examples of storing this data in variable and best way to access this data in a different place?
  • For example I would like to extra the auth token returned into a variable to than use to set the cookie and also use it for other endpoints instead of consistently filtering out this entire single record per use case. If that makes sense
  • tcg.store-1284022517341884436

    TCG.Store

    1 year ago

    Following up here

    I got it all saved to a variable and it's working successfully!
    🙌1