Trouble getting my Post Request API response to a data variable

Total noob here - my apologies for any redundancy or general ignorance.

I’m pulling data from an API that requires the request to be a post. The test returns the exact data that I want and the schema from response also works perfectly.

The issue I’m having is when I’m trying to set the data variable. Here are my steps:

  1. Variables > Data Variables > Add Data Variable > (Select my data source)
  2. I set Data Variable Type to Single Data Record
  3. In the logic flow I delete the Get Record and the Delay and add a Create Record
  4. Set Data Variable > Data (Binding) > Output Value Of Another Node > (Select logic node) Create Record > (Select node output) Response

This is where I get confused - Under response, there are three items:

  1. The list that I’m looking for (list of objects with 44 properties)
  2. Status Code
  3. Status Message

All of the three are marked incompatible.

It does seem to allow me to select the Response, so I save and move on, but when I try to use the variable on the page, my only option says ‘id’ and it returns nothing.

I must be missing something obvious. Can anyone tell me where I got turned around? Many thanks for your help!!!

Hey,

If you are looking for a list, you should be using a Collection of data records (a list of objects) type variable instead of a Single data record (an object). Also, make sure to define the schema of the objects in the Data resource configurator → The resource you are using → Get collection → Schema, so that your data variable gets the correct properties.

1 Like

Hi Cecilia,

Thanks for responding!

That seemed to make more sense to me as well.

However, this particular API is requiring I use a POST to get the data. That does work when testing - I run the post query with the right parameters and it will return the data that I’m looking for. I just can’t seem to convert it to a data variable.

I was trying to do something along the same lines as the food data tutorial - similarly, my request returns a json file with a lot of information that I believed could be parsed and used within the app once converted to a data variable.

Does any of that make any sense?

Thanks again for your help!

Hey,

Yes, your approach sounds good with creating a data variable and then changing the Get record collection to a Create record to get the data. But since you are looking for a list of data, you will need a Collection type data variable, which gets its schema from what is configured in the Data resources tab → Get Collection → Schema. So you will need to manually set the properties of the data list there. That way the data variable will have the correct properties and you will see more than just id as an option. It’s a bit unintuitive, since you are using POST to get the data but the data variable gets it schema as is defined in GET :slight_smile:

Also with the issues of binding the response to the data variable, I think you might need to use a formula. So set the data variable with outputs["Create Record"].response.<the list> or something like that. It might complain about incompatible but it could work.

Thanks Cecilia! I think I’m getting there but I’m still missing something.

I have the Get Collection Schema manually set - I took two of the 44 properties from the response and duplicated them under the Get Collection Schema just to try to work with the data.

This does allow me to point to it using the formula just as you described. However, when I try to use it on my page (I’m just trying to get it to show the data in a list item) my emulator shows nothing.

Taking a second look at the formula I’m using when setting the binding for the data variable, it seems to recognize the schema as set in the Post section of the data resource configurator. I’m using outputs[“Create record”].response. It pulls all of the relevant data but at the bottom under Validation it says Object Type is not assignable to List Type.

If I use outputs[“Create record”].response. or anything further, it says the same thing.

So. It’s obviously pulling the correct data. I just must be missing something elementary in terms of pointing to it on the page.

Being that the page side seems to use the Get schema while the data variable formula seems to be using Post schema, I assume the problem is somewhere in there. Do you have any idea what I may be missing?

Thank you for your help!

Yeah this is a bit tricky :grin: so the Create Record assumes by default that the response is an object and assumes its schema to be th eone configured in create Record in the data configurator, even though in your case it is not.

So just clearing up, if you at the moment have a Collection of records type data variable, that has the schema of the Get Collection configurations. Create record thinks that its response is an object, so it complains about the object <> list assigneability. But if you use a formula you should be able to ignore the warnings and it should work, but it seems like not.

One thing to check is if the request is going through alright, so if you check your developer tools (right click on your browser → Inspect → Open the network tab) and then open your preview page where the list should be, you should see the Create request in the list. There you can see the response, if any data is actually coming through. You can also set an alert to the second output of the Create Record function to check if the request fails. Thirdly, you can bind you data variable to a text component on your page (use ENCODE_JSON formula) to see what value the data var gets.

So I have it all set up as described. I’m able to point to the correct data via formula, at least as far as the formula dialogue goes. The preview data matches. So we know that it’s correctly calling the data.

However, it is not creating the data variable. What I BELIEVE is happening is that since we are getting the data via a POST call, it’s expecting an object with 3 properties because there are three parameters in the request body. So somehow that is preventing it from creating the data variable according to the desired schema, which is a list of objects with 46 properties.

Are you aware of any workarounds?

Thanks!

Hey,

The data shown in the editor when creating your app doesn’t actually reflect if the data gets called when you use the app. So even if the formula editor shows correct data, there might still be issues with the data requests when you use the preview app.

So if the data variable on your page is a Collection of records type of data variable, it will get its schema from the Data Resource tab’s Get Collection response schema configurations. Only New data record types take the request schema of Create Record, but that shouldn’t be your case as you want don’t want to create a new record into your database, you just want to request the list of records from your database. So make sure your data variable is a Collection of Records.

Did you check your network tab for any errors with the request itself? Or add e.g. alerts to your app that would display the results of the Create Record to see what sort of data you are getting? This would be the next steps.

Hey any updates on this ? Even I want to consume the post request’s response but unable to set the variables

I never did get it to work. I gave up and decided to use a workaround. I use Xano for my backend (Xano makes it super easy to customize the function stack in a custom API). From Appgyver I call my API via Xano, which in turn calls the third party API and returns the data in a format useable by Appgyver. It’s kind of a backwards way to do it but it works and it’s suitable for my purposes (My app is just for internal use for my small business).

1 Like