1

I'm requesting a list of possible stock ticker symbols from the Yahoo Stock Lookup API, I used the CORS Anywhere service to avoid problems. Unfortunately the original json response from the Yahoo API gets formatted as 'text' in the CORS anywhere 'error' property.

I used this previously asked question as a reference on how to access nested properties.

this is what the json reponse looks like:

{
  "headers": {
    "normalizedNames": {},
    "lazyUpdate": null
  },
  "status": 200,
  "statusText": "OK",
  "url": "https://cors-anywhere.herokuapp.com/http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback",
  "ok": false,
  "name": "HttpErrorResponse",
  "message": "Http failure during parsing for https://cors-anywhere.herokuapp.com/http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback",
  "error": {
    "error": {
      "line": 9848,
      "column": 56,
      "sourceURL": "capacitor://localhost/vendor-es2015.js"
    },
    "text": "YAHOO.Finance.SymbolSuggest.ssCallback({\"ResultSet\":{\"Query\":\"Amd\",\"Result\":[{\"symbol\":\"AMD\",\"name\":\"Advanced Micro Devices, Inc.\",\"exch\":\"NMS\",\"type\":\"S\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Equity\"},{\"symbol\":\"DOX\",\"name\":\"Amdocs Limited\",\"exch\":\"NMS\",\"type\":\"S\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Equity\"},{\"symbol\":\"AMDVX\",\"name\":\"American Century Mid Cap Value Fund R6 Class\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDWX\",\"name\":\"Amana Mutual Funds Trust Developing World Fund Investor\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDAX\",\"name\":\"AMIDEX35 Israel Fund Class A\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDEX\",\"name\":\"AMIDEX35 Israel Mutual Fund\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDCX\",\"name\":\"AMIDEX35 Israel Fund Class C\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDRX\",\"name\":\"American Beacon Mid-Cap Value Fund R6 Class\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDLY\",\"name\":\"Amada Holdings Co., Ltd.\",\"exch\":\"PNK\",\"type\":\"S\",\"exchDisp\":\"OTC Markets\",\"typeDisp\":\"Equity\"}]}});"
  }
}

This is what I tried:

return this.yahooResult.subscribe(data => {return data['error']['text']['ResultSet']['Result']['symbol']});

I'm trying to access "symbol" : "AMD" from the Yahoo API response that is nested in the "text" property of the CORS repsonse.

I don't get much information from the error: ⚡️ [error] - ERROR

sampjr
  • 103
  • 1
  • 2
  • 14

1 Answers1

1

You don't have json there, you have a javascript snippet:

YAHOO.Finance.SymbolSuggest.ssCallback()

With some escaped text passed into it.

It's not a case of parsing this, its a case of fixing the error.

I think you are using the wrong API call. It has a callback parameter in it which is wrapping the reply in a function and breaking cors-anywhere's ability to parse the response.

The url you should be using is:

http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en

Not:

http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback

Then just plain JSON gets returned and cors-anywhere should be able to parse it.

rtpHarry
  • 13,019
  • 4
  • 43
  • 64