Specify an API Key as a Request Header

Having an issue specifying an API key for an online service in an INSERT FROM URL.

The example below, as a CURL option, doesn't work. Have tried lots of others.

"--header "x-api-key:"" & API_KEY



If you're going to include quotes then you need to escape them:

"--header \"x-api-key:\"" & API_KEY

You may want to use something like this: How to Send SSL Certificate with “Insert from URL” Request | FileMaker 19
to make your life a lot easier in not having to deal with the quoting, plus getting type-ahead for the available cURL options.

Thanks, but I actually had (but didn't post correctly) the header quoted as you did, but it doesn't work. POSTMAN works fine, but I can't see exactly how POSTMAN defines the header, other than in the console, I see the api key header.


Oh? You mean that it is not a specified header that you set in Postman but it somehow automagically appears?
Is there a redirect going on?

No, sorry, it is a header set in a postman GET request but not shown in URL itself.


How about having the cURL options calc specified as:

"--header \"x-api-key: " & API_KEY & "\""

... which evaluates to:

--header "x-api-key: xxxxxxxxx"

... assuming API_KEY is a Custom Function that simply returns the actual API key, e.g. 'xxxxxxxxx'.

Dig around in the Postman UI until you discover the tool that provides you with the equivalent of what that call is doing.


The closest I could find is the "Console" which shows the header, but doesn't show the Request syntax ("--header", or whatever).

What way are you referring to?


On the right hand side of the window beneath the SAVE button there are two links. One for cookies and one for code. Click the code link and postman will generate the equivalent code in the programming language of your choice.



Thanks Malcolm. The environment is FileMaker. :slight_smile:

Modern programming languages let you set request headers in an object-based way, like you see below, removing all the mystery and clumsy time-consuming, and often frustrating, hard-coded string attempts FMP still requires.

Better object-based way to set headers and other Request properties:
myURLConnection.setRequestProperty ("x-api-key", theKey);
myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

In any case, the request is working now and I wanted to thank you for pointing out that portion of POSTMAN!

Thanks again!

If that is the syntax style you prefer then I guess you didn't look at the cURL CF library I mentioned. It allows you to construct your syntax exactly like this.

There's no reason to fiddle with trying to hard code a properly escaped string unless you really want to.


You're right. I didn't have time yet to look at your nice library.

And, thank you for creating it and filling in an obvious functionality gap and a cause for lots of forum postings! :slight_smile:

Have a good one, Wim.

Maybe you can get FMI to add a little CURL builder on the CURL options page also based on what you did. Small additions like that would add a lot of polish.

Just another idea.