Skip to main content
Solved

WebAPI - Addressing field name with spaces in Fetch() request

  • July 19, 2023
  • 2 replies
  • 33 views

Forum|alt.badge.img+4
  • Participating Frequently
  • 5 replies

This seems like a very basic question but search hasn't yielded me an answer.

How do I set a field with spaces in the name using a fetch() request? 

const res = await fetch('https://api.airtable.com/v0/xyz/Estimates', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.AIRTABLE_TOKEN}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ "records": [ { "fields": { Client: [client.id], JSON: escapedJson, Total: total, Screens: screens, Outside Only: flags.outsideOnly } }, ] }) });

Best answer by Jack_Manuel

Wrap the field name in double quotes

 

body: JSON.stringify({ "records": [ { "fields": { Client: [client.id], JSON: escapedJson, Total: total, Screens: screens, "Outside Only": flags.outsideOnly } } ] })

I tend to just wrap all JSON params in quotes to save remembering when I'm supposed to.

 

2 replies

Jack_Manuel
Forum|alt.badge.img+18
  • Brainy
  • 80 replies
  • Answer
  • July 19, 2023

Wrap the field name in double quotes

 

body: JSON.stringify({ "records": [ { "fields": { Client: [client.id], JSON: escapedJson, Total: total, Screens: screens, "Outside Only": flags.outsideOnly } } ] })

I tend to just wrap all JSON params in quotes to save remembering when I'm supposed to.

 


Forum|alt.badge.img+4
  • Author
  • Participating Frequently
  • 5 replies
  • July 19, 2023

Oh well that's easy!