# Proper API call formatting

**URL:** <https://forum.ipums.org/t/proper-api-call-formatting/5552>\
**Category:** IPUMS API\
**Created:** [December 11, 2023, 2:40am UTC](https://forum.ipums.org/t/proper-api-call-formatting/5552 "2023-12-11T02:40:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Poor](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/daniel_poor/32/697_2.png) [@Daniel\_Poor](https://forum.ipums.org/u/Daniel_Poor)\
**Post date:** [December 11, 2023, 2:40am UTC](https://forum.ipums.org/t/proper-api-call-formatting/5552/1 "2023-12-11T02:40:43Z")

</div>

Hi there.  
I’m using Python to make API calls to NHGIS.  
I’m a rudimentary coder and now stumped with what seems to be an API syntax issue.

**This works:**  
my\_key = “xxxxxxx”  
my\_headers = {“Authorization”: my\_key}

# This one works

url = “[https://api.ipums.org/metadata/nhgis/datasets?version=2](https://api.ipums.org/metadata/nhgis/datasets?version=2)”  
response = requests.get(url, headers=my\_headers)

However, any permutation – variable or hard coded – of calling table files gives me a 404.  
dataset = “1840\_cPop”  
table = “NT2”

# **All of these get 404 error code**

url = “[https://api.ipums.org/metadata/nhgis/datasets/{dataset}/data\_tables/{table}?version=2](https://api.ipums.org/metadata/nhgis/datasets/%7Bdataset%7D/data_tables/%7Btable%7D?version=2)  
…redacted to get by the blog filter limitation/datasets/{dataset}?version=2”  
…redacted to get by the blog filter limitation/datasets/1840\_cPop?version=2"  
Any guidance on what I am doing wrong will be much appreciated.

DP

---

<div class="post-metadata">

**Author:** ![fran](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/fran/32/363_2.png) [@fran](https://forum.ipums.org/u/fran)\
**Post date:** [December 11, 2023, 3:31pm UTC](https://forum.ipums.org/t/proper-api-call-formatting/5552/2 "2023-12-11T15:31:02Z")

</div>

Hi Daniel!

Without seeing your actual code I cannot be sure, but I see a couple of potential issues.

- There is no `1840_cPop` dataset, but there is `1840_cPopX`

- To do string interpolation in Python you need to use [f-strings or one of the other string interpolation methods](https://www.programiz.com/python-programming/string-interpolation) e.g.

```auto
dataset = "1840_cPopX"
table = "NT2"
url = f"https://api.ipums.org/metadata/nhgis/datasets/{dataset}/data_tables/{table}?version=2"

```

I wrote a test script making those adjustments and verified a 200 response code.

Let me know if you are still having issues!

Thanks,  
Fran

---

<div class="post-metadata">

**Author:** ![fran](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/fran/32/363_2.png) [@fran](https://forum.ipums.org/u/fran)\
**Post date:** [December 11, 2023, 3:53pm UTC](https://forum.ipums.org/t/proper-api-call-formatting/5552/3 "2023-12-11T15:53:06Z")

</div>

PS - I’ve edited my previous reply to remove the reference, but in case you’ve already read it, although we do have NHGIS support on our `ipumspy` roadmap unfortunately we haven’t finished that yet so that’s not an option at the moment.

---

<div class="post-metadata">

**Author:** ![Daniel\_Poor](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/daniel_poor/32/697_2.png) [@Daniel\_Poor](https://forum.ipums.org/u/Daniel_Poor)\
**Post date:** [December 11, 2023, 5:40pm UTC](https://forum.ipums.org/t/proper-api-call-formatting/5552/4 "2023-12-11T17:40:21Z")

</div>

Fran,  
Thank you. It was another PICNIC.\*  
DP

- Problem in chair, not in computer.
