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 comentarios

Luca
Luca el 26 de Jul. de 2025
The error arises also when copying and pasting the code from the help webpage.
dpb
dpb el 26 de Jul. de 2025
Editada: dpb el 26 de Jul. de 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 el 26 de Jul. de 2025
Thanks, I have submitted the official request.
dpb
dpb el 26 de Jul. de 2025
Editada: dpb el 26 de Jul. de 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 el 26 de Jul. de 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?
Luca
Luca el 26 de Jul. de 2025
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 el 26 de Jul. de 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 el 26 de Jul. de 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 el 26 de Jul. de 2025
Editada: dpb el 26 de Jul. de 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 el 29 de Jul. de 2025
Movida: dpb el 29 de Jul. de 2025
Hi,
Same error with MATLAB R2024b and windows OS.
Best
Yvan Becard
Yvan Becard el 19 de Ag. de 2025
Same error with MATLAB R2025a and Ubuntu 24.04.3 LTS

Iniciar sesión para comentar.

 Respuesta aceptada

Meet
Meet el 29 de Jul. de 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 comentarios

Luca
Luca el 29 de Jul. de 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 el 29 de Jul. de 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
Yvan Becard
Yvan Becard el 2 de Sept. de 2025
Support does not answer. Where can I find the updated fetch file?
dpb
dpb el 2 de Sept. de 2025
How did you contact them? If email, it'll take a while; they will answer the phone during US EST business hours.
Yvan Becard
Yvan Becard el 3 de Sept. de 2025
I was redirected to this page by a Matlab employee:
Does anyone know how to make FRED© REST work?
Edu Benet Cerda
Edu Benet Cerda el 3 de Sept. de 2025
Editada: Edu Benet Cerda el 3 de Sept. de 2025
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:
Yvan Becard
Yvan Becard el 8 de Sept. de 2025
Thanks a lot Edu

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Help and Support en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 26 de Jul. de 2025

Comentada:

el 8 de Sept. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by