Help

Getting value of lookup field from API

Topic Labels: API
9659 6
cancel
Showing results for 
Search instead for 
Did you mean: 
ackerman
4 - Data Explorer
4 - Data Explorer

Hello! I’m relatively new to Airtable. I have a view that has columns that are lookups from other tables. When I pull the table data into a web app that I’m building, I get what looks to be random string references anywhere a lookup or linked value is. If anyone has thoughts on how I can grab the value of that field instead of the reference, I’d be super appreciative.

Here is an example of my code:
When I have the results returned to me, and I get a field value for a non linked or lookup column like this:

response.data.records[i].fields.Date

I get the date, as expected. But if I reference a linked or lookup column, like this (the Project column is linked to the projects table…):

response.data.records[i].fields.Project

I get something like this returned:

recNmHYjQBITjdJdb

rather than the string of the project’s name.

Any help or advice is super appreciated!

6 Replies 6
Andrew_Johnson1
8 - Airtable Astronomer
8 - Airtable Astronomer

You will need to make another request to retrieve the actual data.
In your case “recNmHYjQBITjdJdb” is the “id” of the record in the “Project” table

You will need to make a GET request to

https://api.airtable.com/v0/xxxxxxx/Project/recNmHYjQBITjdJdb

(where xxxxxxx is your base) to get the actual data (i.e. the project’s name)

If you check out the API Docs there will be a section called “Retrieve a record”
You will want to go over that

openside
10 - Mercury
10 - Mercury

Another approach would be to include a lookup field in your table that pulls in the ‘Name’ field of project. You’ll have 2 fields that show the project name now, but via the api the new field will be the actual project name and not the record id. You can just hide it in your table since its not needed other than for the api calls. This will save you an api call.

Hey Openside, how would I include a lookup field in my table?

Just the standard lookup field (documentation here:
https://support.airtable.com/hc/en-us/articles/202576519-Guide-to-formula-lookup-count-and-rollup-f...
)

You would reference the linked table, then select the ‘Name’ column. Now you have 2 columns showing the name, but in the api this new ‘lookup’ column with be the text Name instead of the ID.

Hope that’s clear.

Dan

I tried your suggestion and this is the response I’m getting…

{
"records": [
    {
        "id": "rec00MzFEFQKIilMt",
        "fields": {
            "DrugName": "percocet",
            "sideEffects": "Mild Side Effects",
            "condition": "buldging/ruptured disc",
            "Benefits": "Pain is now under control to some degree.  Still have pain throughout body and down legs.  Before the medication I would not be able to get out of bed for sometimes days.  Even when I could get out of bed I would not be able to sit up or walk for more than 30 minutes before I had to lay down.  Now I am able to be up all day, walk and sit up for more than 3-4 hours at a time.",
            "sideEffectsComments": "It sometimes makes me feel \"high\", vision problems, coordination problems.",
            "DrugName copy": [
                "recuPnBm0QPjI1wL0"
            ],
            "lookup": [
                "percocet"
            ]
        },
        "createdTime": "2018-11-01T05:41:33.000Z"
    },

Is it possible to display the “id” as the actual drug name instead of the reference id? Maybe you know of an easier way to accomplish what I’m trying to do … which is to basically to be able to make a request using the drug name and not the ID… is this possible? Thanks for your help and I appreciate your patience with me :slightly_smiling_face:

Hi Zo,

Not sure if you still need the answer but I reply anyway for anyone who has experienced the same problem.

No, you cannot replace the id filed as it’s used by Airtable to identify records. For such situation, I would parse the response JSON into my new defined object with the field ‘id’ to be used in requests and ‘name’ for my own convenience.

Regards,

Alex