Security error using fred/fetch

Hi,
I recently updated the Mac software to Sequoia, and started to receive the following error for a code that has always worked before:
Error using fred/fetch
Unable to retrieve data. Verify valid security request.
Do you know how to fix this? I have updated the Matlab version to the latest, and the error still persists.
Thanks!

11 Commenti

Luca
Luca il 26 Lug 2025
The error arises also when copying and pasting the code from the help webpage.
dpb
dpb il 26 Lug 2025
Modificato: dpb il 26 Lug 2025
url = 'https://fred.stlouisfed.org/';
c = fred(url);
series = 'DEXUSEU';
d=fetch(c,series)
Error using fred/fetch (line 60)
Unable to retrieve data. Verify valid security request.
Google says FRED requires a valid API key downloaded from the site and somehow integrated into the connection object. I can find no reference to how this is handled in the MATLAB documentation; apparently there must have been some behind the scenes machinations going on that the update has broken.
Think another you'll have to submit this to Mathworks as an official support request/bug at <Product Support Page> unless somebody who has previously figured it out stumbles by. Unfortunately, Mathworks won't respond over the weekend...
Luca
Luca il 26 Lug 2025
Thanks, I have submitted the official request.
dpb
dpb il 26 Lug 2025
Modificato: dpb il 26 Lug 2025
It appears that when you get the API code, it is set as an environment variable. I don't know how that is done in MAC OS. It would appear given the lack of any comment on it by the fetch documentation that the TB must do this behind the scenes on installation with a generic API key Mathworks ships. Any chance of being able to discover what that might have been on your system prior to the upgrade?
Configure API Key in MATLAB:
  • Environment Variable (recommended): For better security and reusability, you can set your FRED API key as an environment variable (e.g., FRED_API_KEY).
Alternatively, reinstalling the toolbox would probably do the trick...
Luca
Luca il 26 Lug 2025
Thanks for looking into this. After the problem has occurred, I downloaded the new version of Matlab and re-installed all the packages, so the update seems not to be working. The fred command is from the Datafeed toolbox.
Can you explain how to retrieve/update the API key?
When I create the connection with the fred command, the output is the following:
c = fred('https://fred.stlouisfed.org/')
c =
fred with properties:
URL: 'https://fred.stlouisfed.org/'
IP: []
Port: []
DatetimeType: []
DataReturnFormat: []
Perhaps I need to inset manually the IP?
dpb
dpb il 26 Lug 2025
Navigate to the FRED site and there are links to follow...this will be your own as opposed to a generic one that must have been somehow tied into the Datafeed TB (which I don't have, so don't know anything about what it actually did/does other than what is in the documentation, which doesn't mention the API key at all). That won't be a problem it would appear it is a free service just for the signing into although I've never used it...
Luca
Luca il 26 Lug 2025
Thanks a lot. I've created an account of FRED and obtained the API key. How can I use that now to download the series?
dpb
dpb il 26 Lug 2025
Modificato: dpb il 26 Lug 2025
Set the environment variable to that key value and theory says fetch should find it...I've never seen a Mac since Apple II days so I've no idea how you actually do that...it may have to be at the system level before you start the MATLAB session again, however, for it to be visible, but you can try the MATLAB setenv function in the active session and see if the toolbox reads the environment dynamically or only caches it on startup.
Apparently, while not recommended practice, you can add it as a named parameter in the fred function call to create the object.
Gauthier
Gauthier il 29 Lug 2025
Spostato: dpb il 29 Lug 2025
Hi,
Same error with MATLAB R2024b and windows OS.
Best
Same error with MATLAB R2025a and Ubuntu 24.04.3 LTS

Accedi per commentare.

 Risposta accettata

Meet
Meet il 29 Lug 2025
Hi Luca,
I was facing a similar issue and figured out that the FRED website recently changed its API and the built-in "fetch" command is no longer able to access the data. This issue can be resolved by downloading the updated "fetch" function and replacing the old function in the toolbox.
Please rename the MATLAB Script "fetch" to "fetch_old" in the below folder on your macOS:
/Applications/MATLAB_R2025a/toolbox/datafeed/datafeed/@fred/
After, please insert the new "fetch" function into the above location. After doing so, the "fetch" function will be able to retrieve data from the FRED website. This set of operations may require administrator privileges.
Note that because of this API change, the output of "fetch" is slightly different and now only includes "SeriesID" and "Data". Also, the "Data" field in the return structure now contains a cell array with an array of doubles, a table or a timetable depending on the input property "DataReturnFormat". Previously, it was either an array of doubles, a table or a timetable not nested in a cell array.
An alternative solution is to use the https://www.mathworks.com/matlabcentral/fileexchange/68247-fred-rest-for-matlab support package on MATLAB File exchange. However, this requires an API key from the FRED website, and has some syntactical changes.
I hope this helps resolve the issue!

7 Commenti

Luca
Luca il 29 Lug 2025
Thanks, this helps a lot. Do you know where to download the updated function fred from? Re-installing the package does not seem to work.
Meet
Meet il 29 Lug 2025
Currently I dont have that file with me you can request the file by reaching out to MathWorks Technical Support: https://www.mathworks.com/support/contact_us.html
Support does not answer. Where can I find the updated fetch file?
dpb
dpb il 2 Set 2025
How did you contact them? If email, it'll take a while; they will answer the phone during US EST business hours.
I was redirected to this page by a Matlab employee:
Does anyone know how to make FRED© REST work?
get an API key from the fred website: St. Louis Fed Web Services: API Key
And the code as:
c = fredrs(<KEY>);
tt = c.series('NYGDPPCAPKDWLD','observations');
tt.observations{1}
Follow the api options described here:
Thanks a lot Edu

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Tag

Richiesto:

il 26 Lug 2025

Commentato:

il 8 Set 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by