Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the NSF award API endpoint #2233

Closed
jeanetteclark opened this issue Dec 7, 2023 · 8 comments · Fixed by #2244
Closed

Fix the NSF award API endpoint #2233

jeanetteclark opened this issue Dec 7, 2023 · 8 comments · Fixed by #2244
Assignees
Labels
ADC CI-09 Enhanced data submission tools & portals (ADC deliverable) arctic data center bug Priority: Critical
Milestone

Comments

@jeanetteclark
Copy link
Collaborator

Describe the bug

Currently, for the NSF award lookup on the ADC, metacatUI looks at https://api.nsf.gov/services/v1/awards.json. This endpoint has a redirect that doesn't work so well and was causing failing award lookups in metadig engine. I changed the proxy in our apache config to research.gov/awardapi-service/v1/awards.json. I think that at a minimum the metacatUI lookup should move to that endpoint, and probably it should be using the proxy instead. @mbjones indicated that this might be overridden in a config somewhere so possibly a non issue, but the award lookup doesn't seem to be working for me right now.

@mbjones
Copy link
Member

mbjones commented Dec 7, 2023

Thanks for the report, @jeanetteclark. The reason that we used the proxy in the first place was to bypass Same Origin restrictions on 3rd party API access. I'm not sure what changed there, maybe we fixed it through CORS headers? In any case, @robyngit and @rushirajnenuji, this is a problem that needs to get fixed ASAP, as it is hitting the datateam members. Could one of you look into it -- hopefully it will be a minor issue. Thanks.

@jeanetteclark
Copy link
Collaborator Author

FYI I switched the apache config back. The award lookup is still not working in metacatUI even with the old config. I also checked with the current datateam and they say the UI lookup has not worked for a while now.

@robyngit
Copy link
Member

Notes:

@mbjones
Copy link
Member

mbjones commented Jan 10, 2024

Another report of problems with the award lookup from RT today:

It looks like I need to provide overview info on the dataset and then link it with my NSF grant. However, when I type in the award number (or anything) in the funding box, nothing emerges from the search.

@robyngit robyngit added this to the 2.28.0 milestone Jan 10, 2024
@robyngit
Copy link
Member

Updating the ADC config to use the new endpoint for the grantsUrl did not resolve this NSF award lookup issue. The URLs formed by MetacatUI were valid, in that they returned a 200 status, but the dropdown in the UI still did not appear. In the browser, the URLs consistently gave 0 results. Updating the grantsUrl to remove the ?id= suffix from the URL did allow the endpoint to return the expected results, but the dropdown in the UI still did not appear. This suggests that the issue extends beyond just the endpoint URL configuration, and that there are deeper issues in the UI component handling or data processing within MetacatUI. Further investigation is needed to resolve the UI dropdown issue fully.

The grantsUrl setting that formed valid URLs was: "https://www.research.gov/awardapi-service/v1/awards.json?id="

The search term "arctica" should return results.

Here is an example query that works in the browser: https://www.research.gov/awardapi-service/v1/awards.json?keyword=arctica&printFields=title,id&callback=jQuery191024293065478125508_1704926101036&_=1704926101037

@robyngit
Copy link
Member

robyngit commented Jan 11, 2024

Looking further into this, the request to the awards API is failing because of a CORS issue: the response is blocked by the same-origin policy. It appears that we were previously getting around this by requesting the API to return JSONP (JSONP is not subject to the same-origin policy). Although "callback" is still a valid parameter accepted by the API, it looks like the response is no longer being wrapped in a callback function. I tested this both in the browser and with curl, and the response is plain JSON, not JSONP. I also tried the same request with the old endpoint, and using the "jsonp" parameter instead of "callback"; neither returned JSONP.

The only documentation that I can find for this API appears to be out of date since it's still referencing the old endpoint. I'm not sure if there's any documentation for the new endpoint, but it would be helpful to know if JSONP is still supported.

Possible solutions:

  1. If JSONP is still supported, we can update our code to request JSONP from the API however it's currently done.
  2. Set up a proxy on our servers to handle the CORS issue.
  3. Contact NSF to see if they can provide a solution or update the CORS policy on their end.

Update: we do in fact already have a proxy set up for this API, it's just not working as expected, investigating this now...

@robyngit
Copy link
Member

Here is the history of this issue (found by @mbjones 🔍 ): #629

@robyngit
Copy link
Member

robyngit commented Jan 11, 2024

After much slack discussion, we've got the problem narrowed down:

Historically MetacatUI was using JSONP to get around NSF's lack of CORS support. NSF did a rewrite of their API (hence the change in the endpoint URL) and it seems that they dropped support for JSONP at the same time. Given the lack of support for CORS and JSONP, MetacatUI will need to make requests via a server-side proxy.

The Apache setup for the ADC was already configured to proxy requests to the NSF award API, however, the proxy needed to be updated to the correct URL (including www and using https instead of http). This has now been corrected, so we can now update MetacatUI to make requests to the proxy and to request and handle JSON responses rather than JSONP.

For the ADC, the grantsUrl that we should use to lookup grants via the proxy is: https://arcticdata.io/research.gov/awardapi-service/v1/awards.json.

Any repository that wants to use the NSF award lookup feature will need to set up their own proxy. We could configure the default grantsUrl to point to a proxy relative to the repository’s own domain. We will need to add documentation to MetacatUI docs about how to set up a proxy for the NSF award API (and how to override the grantsUrl if it differs from the default)

To Do:

  • Update the default grantsUrl to point to a proxy relative to the repository’s domain
  • Update MetacatUI to handle JSON responses rather than JSONP
  • Add documentation to MetacatUI docs about how to set up a proxy for the NSF award API
  • Write tests for these methods

@robyngit robyngit added ADC CI-14 Data search and display improvements (ADC deliverable) ADC CI-09 Enhanced data submission tools & portals (ADC deliverable) and removed ADC CI-14 Data search and display improvements (ADC deliverable) labels Jan 11, 2024
robyngit added a commit that referenced this issue Jan 16, 2024
- Update the default grantsUrl to point to a proxy relative to the repository’s domain
- Remove unused getGrant method from the LookupModel
- Use native fetch API instead of jQuery.ajax to retrieve grants
- Show spinner to indicate that grants are being retrieved (was set up but not used)
- Move some logic from the getGrantAutocomplete method to new, smaller methods
- Add missing JS docs
- Add error handling

Issue #2233
robyngit added a commit that referenced this issue Jan 16, 2024
@robyngit robyngit linked a pull request Jan 17, 2024 that will close this issue
ianguerin pushed a commit to ianguerin/metacatui that referenced this issue Mar 15, 2024
ianguerin pushed a commit to ianguerin/metacatui that referenced this issue Mar 15, 2024
ianguerin pushed a commit to ianguerin/metacatui that referenced this issue Mar 15, 2024
- Update the default grantsUrl to point to a proxy relative to the repository’s domain
- Remove unused getGrant method from the LookupModel
- Use native fetch API instead of jQuery.ajax to retrieve grants
- Show spinner to indicate that grants are being retrieved (was set up but not used)
- Move some logic from the getGrantAutocomplete method to new, smaller methods
- Add missing JS docs
- Add error handling

Issue NCEAS#2233
ianguerin pushed a commit to ianguerin/metacatui that referenced this issue Mar 15, 2024
ianguerin pushed a commit to ianguerin/metacatui that referenced this issue Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADC CI-09 Enhanced data submission tools & portals (ADC deliverable) arctic data center bug Priority: Critical
Development

Successfully merging a pull request may close this issue.

4 participants