Confused about naptan codes not working with API

Hi I was playing with some scripts to get crowding data and manipulate how it was displayed but I keep getting a isFound = False return. I used the gov website for naptan download, used area code 490 for Greater London and then just picked some random naptan codes to feed into the TFL API. If I however try out these codes I found on a github repo they ones work:
ZackaryH8/tube-naptan/blob/master/data/naptan.csv
They seem to be of a different format from what i got on the gov site.

Can someone tell me if I am looking for the naptan ids in the wrong place/wrong way?
example code that works from Repo: 940GZZLUCHX
example code from gov site that doesn’t: 92073 (49029073 doesn’t either)

1 Like

Welcomes @taulpom

The official source for the codes is Download national stop data - NaPTAN - DfT

If you want the CSV version just point your cron job at https://beta-naptan.dft.gov.uk/Download/File/Stops.csv

As I’m just debugging some Naptan codes now I’m finding this is “CHX”

Sorry should have pointed out that 940G (“metro”) - ZZLU (“London Underground”) - CHX the codes from https://content.tfl.gov.uk/station-abbreviations.pdf

1 Like

Hi @taulpom, @briantist this is an excellent question. I’m struggling with it too, as there’s definitely a discrepancy between TFL rest API requirements and Naptan gov file. It’s also not entirely clear what they mean by Naptan code (it would be nice if there was some documentation on this).

@briantist, thanks for the reply, at least it’s now clear how to create this Naptan code manually (not the easiest way). This is only relevant for metro stations, right? But what about the rest of Naptan (the official file you sent has over 450,000 Naptan points)? So if the API (APIs: Details - Transport for London - API) can work with any Naptan, that would give a much more accurate resolution than just metro stations. And since there are no corresponding Naptan API codes in this gov file, this file becomes useless.

So as far as I understand, @taulpom’s question is still valid, and I’d really like to hear comments on this that might give some insight into where the Naptan code is coming from.

1 Like

hi @Golda

Our API only contains codes from the following datasets:

037 Slough
040 Bucks
150 Essex
159 Thurrock
210 Herts
240 Kent
400 Surrey
490 Greater London
910 National Rail
930 Rivers & Ferries
940 Metro Services

920 relates to airports, but I 92073 doesn’t exist in that dataset.

however, we do have an SMS short code that relates to a bus stop:

92023 49000343NE BUCKINGHAM ROAD

which is the following

    <StopPoint Modification="revise" ModificationDateTime="2016-06-08T10:30:01" CreationDateTime="2016-06-08T10:30:01" RevisionNumber="0" Status="active">
      <AtcoCode>49000343NE</AtcoCode>
      <NaptanCode>92023</NaptanCode>
      <Descriptor>
        <CommonName>Buckingham Road Harlesden</CommonName>
        <Landmark>---</Landmark>
        <Street>---</Street>
        <Crossing>--</Crossing>
        <Indicator>Stop B</Indicator>
      </Descriptor>
      <Place>
        <NptgLocalityRef>E0034047</NptgLocalityRef>
        <LocalityCentre>false</LocalityCentre>
        <Location>
          <GridType>UKOS</GridType>
          <Easting>521745</Easting>
          <Northing>183362</Northing>
        </Location>
      </Place>
      <StopClassification>
        <StopType>BCT</StopType>
        <OnStreet>
          <Bus>
            <BusStopType>MKD</BusStopType>
            <TimingStatus>OTH</TimingStatus>
            <MarkedPoint>
              <Bearing>
                <CompassPoint>NE</CompassPoint>
              </Bearing>
            </MarkedPoint>
          </Bus>
        </OnStreet>
      </StopClassification>
      <StopAreas>
        <StopAreaRef>490G00000343</StopAreaRef>
      </StopAreas>
      <AdministrativeAreaRef>082</AdministrativeAreaRef>
    </StopPoint>

This is of the type MKD (On-street Bus / Coach Stop) in the NaPTAN 940 dataset. In the DfT’s data, the SMS code seems to be captured as NaptanCode, whereas we use the AtcoCode as the identifier in our API under naptanId in the Unified API.

Hi @jamesevans!

Thanks for such a quick reply. Now it’s clear to me that API supports not only tube. But it’s still not clear where I can find Naptan points with their description and code. You wrote that “In the DfT’s data, the SMS code seems to be captured as NaptanCode” but in DfT’s data there is no field like SMS code or smth like that. Also you wrote that you use ATCOCode as naptanId Unified API but if you take any ATCOCode from DfT’s file and try to call Unified API (crowding API) so you will always receive no data (“isFound”: false).

Btw, may be this is the terminology problem? You just wrote naptanId but throughout the documentation it is NaptanCode (both in the description of Unified API and field name in the DfL’s file).

Just to clarify. In this thread we are trying to find a list of NaptanCodes with description which will fit that API

The example quoted was 92073, not 92023. It doesn’t affect the argument though as 92073 is also the SMS code for a bus stop, at Aldgate.

Hi @Golda

If only it was just the tube, our jobs would be a lot easier!

Apologies I misread it that code!

Essentially the mapping is as follows:

UAPI DfT
naptanId AtcoCode
smsCode NaptanCode

We take naptanId from the DfT for the datasets provided. The smsCode is taken from our internal systems for bus data. This doesn’t appear as data in the 910, 930 or 940 DfT datasets.

In terms of getting a definitive list, you could call https://api.tfl.gov.uk/StopPoint/Mode/tube and filter down for NaptanMetroStation with mode as tube.

Thanks,
James

Hi @jamesevans!

Thank you very much for your response.According to your answer we can use additional StopPont UAPI for extraction naptanId and after that use that naptanId as Naptan parameter in Crowding UAPI.

I just want to highlight again that ATCOCode in DfT data is not the same that Naptan parameter in Crowding UAPI. I just pick 5 random (for tube stations) examples from DfT and checked that. For instance let’s check “Canary Wharf Underground Station”: for that station ATCOCode from DfT data is 490000038F, so I use that ATCOCode as Naptan parameter in Crowding UAPI and it can not find that data for that Naptan parameter.

btw naptanId from StopPont UAPI also doesn’t work in Crowding UAPI :confused:

Finally!!!

This scheme will definitely work. We can just query all stations we need in StopPont UAPI and after that put it as a parameter into Crowding UAPI. We can use stationNaptan entity (not naptanId) from StopPont UAPI as Naptan parameter in Crowding UAPI. I knew there was a problem with the terminology.

@jamesevans thank you very much for your help!

1 Like

Hi @Golda
Hate to confuse matters further but 490000038F is the ATCOCode/naptanid for a bus stop at Canary Wharf Bus Station, with smscode 76008. Right now I can see buses from five different routes due in the next half hour.

The code for the station itself must be something different but others are better placed to advise for that specific case and - presumably the endgame here? - to extract a definitive list of codes for the stations from TfL’s own data.

Hi @mjcarchive!

Sorry, I can’t understand your question (could you please clarify?). My initial problem was: Where should I find Naptan code parameters for Crowding UAPI. Now as I see we can extract those parameters from another StopPoint UAPI

@Hi Golda

I think the only question I asked was answered in your post immediately above mine, which I hadn’t seen as it was made at much the same time. The main point I was making was that most codes with “station” in their description related to adjacent bus stops rather than the station entities themselves.

Hi @mjcarchive.
Okay. Got it.
Also want to add to my previous message that not all ** stationNaptan** codes from StopPont UAPI might be found in Crowding UAPI . But anyway according to the list of existing modes and data from StopPont UAPI there are 44450 Naptan points which is much more then in file ZackaryH8/tube-naptan/blob/master/data/naptan.csv.

Hi @jamesevans!

Sorry to bother you, but I still can’t get my problem sorted out.

Let me spell it out formally again: I want to create a static database for all the UK transport types that are possible (bus, elizabeth-line, tube, etc), which would consist of: Station/stop name, station/stop coordinates, station/stop occupancy by day of week (json).

For this I did the following:

  1. Collected all possible modes (via this endpoint https://api.tfl.gov.uk/StopPoint/Meta/Modes) - and I got a list of [‘bus’, ‘cable-car’, ‘coach’, ‘cycle’, ‘cycle-hire’, ‘dlr’, ‘elizabeth-line’, ‘interchange-keep-sitting’, ‘interchange-secure’, ‘national-rail’, ‘overground’, ‘replacement-bus’, ‘river-bus’, ‘river-tour’, ‘taxi’, ‘tram’, ‘tube’, ‘walking’]

  2. Using this list from point 1, I compiled a complete list of StopPoints (via this endpoint https://api.tfl.gov.uk/StopPoint/Mode/) and I got a table of 44450 elements with columns “commonName”, “naptanId”, “stationNaptan”, “lat”, “lon”.

  3. By this list from point 2, I wanted to collect crowding data of these StopPoints (through this endpoint https://api.tfl.gov.uk/crowding/Naptan) and under Naptan I independently used both naptanId and stationNaptan.

After doing point 3 it turned out that only 279 out of 44450 StopPoints have crowding information in https://api.tfl.gov.uk/crowding/Naptan endpoint.

My question is, have I done something wrong or is there really no more data in CrowdingAPI?

@Golda

Interestingly I got 309 endpoints:

910GCANWHRF
910GCSTMHSXR
910GFRNDXR
910GLIVSTLL
910GPADTLL
910GTOTCTRD
910GWCHAPXR
940GZZBPSUST
940GZZDLABR
940GZZDLALL
940GZZDLBEC
940GZZDLBLA
940GZZDLBOW
940GZZDLBPK
940GZZDLCAN
940GZZDLCLA
940GZZDLCUS
940GZZDLCUT
940GZZDLCYP
940GZZDLDEP
940GZZDLDEV
940GZZDLEIN
940GZZDLELV
940GZZDLGAL
940GZZDLHEQ
940GZZDLISL
940GZZDLKGV
940GZZDLLCA
940GZZDLLDP
940GZZDLMUD
940GZZDLPDK
940GZZDLPOP
940GZZDLPRE
940GZZDLPUD
940GZZDLRAL
940GZZDLRVC
940GZZDLSHS
940GZZDLSIT
940GZZDLSOQ
940GZZDLSTL
940GZZDLTWG
940GZZDLWFE
940GZZDLWLA
940GZZDLWSV
940GZZLUACT
940GZZLUACY
940GZZLUADE
940GZZLUAGL
940GZZLUALD
940GZZLUALP
940GZZLUAMS
940GZZLUASG
940GZZLUASL
940GZZLUBBB
940GZZLUBBN
940GZZLUBDS
940GZZLUBEC
940GZZLUBKE
940GZZLUBKF
940GZZLUBKG
940GZZLUBKH
940GZZLUBLM
940GZZLUBLR
940GZZLUBMY
940GZZLUBND
940GZZLUBNK
940GZZLUBOR
940GZZLUBOS
940GZZLUBSC
940GZZLUBST
940GZZLUBTK
940GZZLUBTX
940GZZLUBWR
940GZZLUBWT
940GZZLUBXN
940GZZLUBZP
940GZZLUCAL
940GZZLUCAR
940GZZLUCFM
940GZZLUCGN
940GZZLUCGT
940GZZLUCHL
940GZZLUCHX
940GZZLUCKS
940GZZLUCND
940GZZLUCPC
940GZZLUCPK
940GZZLUCPN
940GZZLUCPS
940GZZLUCSD
940GZZLUCSM
940GZZLUCST
940GZZLUCTN
940GZZLUCWL
940GZZLUCWP
940GZZLUCWR
940GZZLUCXY
940GZZLUCYD
940GZZLUCYF
940GZZLUDBN
940GZZLUDGE
940GZZLUDGY
940GZZLUDOH
940GZZLUEAC
940GZZLUEAE
940GZZLUEAN
940GZZLUEBY
940GZZLUECM
940GZZLUECT
940GZZLUEFY
940GZZLUEGW
940GZZLUEHM
940GZZLUEMB
940GZZLUEPG
940GZZLUEPK
940GZZLUEPY
940GZZLUERB
940GZZLUERC
940GZZLUESQ
940GZZLUEUS
940GZZLUFBY
940GZZLUFCN
940GZZLUFLP
940GZZLUFPK
940GZZLUFYC
940GZZLUFYR
940GZZLUGBY
940GZZLUGDG
940GZZLUGFD
940GZZLUGGH
940GZZLUGGN
940GZZLUGHK
940GZZLUGPK
940GZZLUGPS
940GZZLUGTH
940GZZLUGTR
940GZZLUHAI
940GZZLUHAW
940GZZLUHBN
940GZZLUHBT
940GZZLUHCH
940GZZLUHCL
940GZZLUHGD
940GZZLUHGR
940GZZLUHGT
940GZZLUHLT
940GZZLUHNX
940GZZLUHOH
940GZZLUHPC
940GZZLUHPK
940GZZLUHR4
940GZZLUHR5
940GZZLUHRC
940GZZLUHSC
940GZZLUHSD
940GZZLUHSK
940GZZLUHSN
940GZZLUHTD
940GZZLUHWC
940GZZLUHWE
940GZZLUHWT
940GZZLUHWY
940GZZLUICK
940GZZLUKBN
940GZZLUKBY
940GZZLUKEN
940GZZLUKNB
940GZZLUKNG
940GZZLUKOY
940GZZLUKPK
940GZZLUKSH
940GZZLUKSL
940GZZLUKSX
940GZZLUKWG
940GZZLULAD
940GZZLULBN
940GZZLULGN
940GZZLULGT
940GZZLULNB
940GZZLULRD
940GZZLULSQ
940GZZLULVT
940GZZLULYN
940GZZLULYS
940GZZLUMBA
940GZZLUMDN
940GZZLUMED
940GZZLUMGT
940GZZLUMHL
940GZZLUMMT
940GZZLUMPK
940GZZLUMRH
940GZZLUMSH
940GZZLUMTC
940GZZLUMVL
940GZZLUMYB
940GZZLUNAN
940GZZLUNDN
940GZZLUNEN
940GZZLUNFD
940GZZLUNGW
940GZZLUNHA
940GZZLUNHG
940GZZLUNHT
940GZZLUNKP
940GZZLUNOW
940GZZLUNWH
940GZZLUNWY
940GZZLUOAK
940GZZLUODS
940GZZLUOSY
940GZZLUOVL
940GZZLUOXC
940GZZLUPAC
940GZZLUPCC
940GZZLUPCO
940GZZLUPKR
940GZZLUPLW
940GZZLUPNR
940GZZLUPRD
940GZZLUPSG
940GZZLUPVL
940GZZLUPYB
940GZZLUQBY
940GZZLUQPS
940GZZLUQWY
940GZZLURBG
940GZZLURGP
940GZZLURKW
940GZZLURMD
940GZZLURSG
940GZZLURSM
940GZZLURSP
940GZZLURSQ
940GZZLURVP
940GZZLURVY
940GZZLURYL
940GZZLURYO
940GZZLUSBC
940GZZLUSBM
940GZZLUSEA
940GZZLUSFB
940GZZLUSFS
940GZZLUSGN
940GZZLUSGP
940GZZLUSGT
940GZZLUSHH
940GZZLUSJP
940GZZLUSJW
940GZZLUSKS
940GZZLUSKT
940GZZLUSKW
940GZZLUSNB
940GZZLUSPU
940GZZLUSRP
940GZZLUSSQ
940GZZLUSTM
940GZZLUSUH
940GZZLUSUT
940GZZLUSVS
940GZZLUSWC
940GZZLUSWF
940GZZLUSWK
940GZZLUSWN
940GZZLUTAW
940GZZLUTBC
940GZZLUTBY
940GZZLUTCR
940GZZLUTFP
940GZZLUTHB
940GZZLUTMH
940GZZLUTMP
940GZZLUTNG
940GZZLUTPN
940GZZLUTWH
940GZZLUUPB
940GZZLUUPK
940GZZLUUPM
940GZZLUUPY
940GZZLUUXB
940GZZLUVIC
940GZZLUVXL
940GZZLUWAF
940GZZLUWBN
940GZZLUWCY
940GZZLUWFN
940GZZLUWHP
940GZZLUWHW
940GZZLUWIG
940GZZLUWIP
940GZZLUWJN
940GZZLUWKA
940GZZLUWKN
940GZZLUWLA
940GZZLUWLO
940GZZLUWOF
940GZZLUWOG
940GZZLUWOP
940GZZLUWPL
940GZZLUWRP
940GZZLUWRR
940GZZLUWSD
940GZZLUWSM
940GZZLUWSP
940GZZLUWTA
940GZZLUWWL
940GZZLUWYC
940GZZLUWYP
940GZZNEUGST

1 Like

Hi @Golda

For crowding, only London Underground & Elizabeth line stations are in scope.

The full details are contained in Joe’s post

Thanks,
James

1 Like

@briantist really interesting. I’ll check it out again.

@jamesevans thanks for the replay, things are much clearer now.

1 Like