Best way to store entire data from an API call on the page so it can be reused?

Hey all,

I have a SC Action API Call that gets about 50 datapoints.
I use a SC Form on the front end to send the data to enrich on to the SC Action.
By putting an ‘output’ on the SC Action API Call I can get the data back to the page to show the new info to the user.

However, I feel this isn’t he right way to store the information so that the user could save this information to a different DB table.

I’ve tried to put Data Detail on the element I display the returned info but just can’t get that to work - so wondering what would be recommended, is there anyway to simply store the full data?

You could store it in local storage.

Thanks Jon, thought about this - but the api returns largely the same, but often different amounts of data - so thought there might be an option to just store the fully returned schema. As I understand in the data store - it needs each variable manually created. I’ll re read the info you are pointing me towards in case there is an answer in there I missed

What about a variable?

You are no doubt seeing all this a lot simpler than I am.

A variable as I understand it is one value, the api data that gets returned in JSON has about 50/60 data points. The datapoints/schema remains the same but the amount of data for each one changes. If I wanted to use variables, I’d need to create the 50/60 in the Data store?

No, I mean just store the whole output in a single AC variable as a json.

1 Like

They seem like they are one-dimensional in the UI but varaiables/local storage can hold whatever you set their value to (numbers, strings as well as arrays and objects). When using the setValue function (maybe on success of a SC connect/API call) assign the response to the variable.

The schema won’t be available in the picker but you can still access it in the same way as a normal variable (e.g. var1.value.data.level1.indexname)

1 Like

Just out of curiosity @bpj what exactly is the ‘indexname’ you mention? You had it in your response to me yesterday as well?

I’d have thought the index number is the row number like [0]. But what is the index name?

if array it will be like array[0]
but if object it will be object.firstname

Ok, that makes a bit of sense. The difference is if its an array or object. Ta

Thank you @bpj and @JonL - I did no realise that, it did indeed some one-dimensional. If I wanted to store a full JSON as a variable, would this be type ‘array’ or simply ‘text’ ?

e.g.
I have api_addresslook that looks up addresses. I could assign it to a variable on success (in the API Data Source use dynamic event > success)


For this test, I am assigning it to a variable called var_testapi
In the picker I selected the data element of the API call as the value - this will store the whole response.
I could reference an element as:
var_testapi.value.latitude
or maybe
var_testapi.value.addresses[0].postcode

The difficulty in doing it this way is that you have to make these references manually, they will not be in the UI picker.

3 Likes

Thank you @bpj - really appreciate you going into detail there. My data comes directly from the form output on the server side, rather than any API / Connects on the F/E - so perhaps that’s why things haven’t gone so smoothly - but I’m going to try this on form success to add to a variable.

Appreciate everyone’s feedback!