I'm trying to retrieve Canvas data for a project where I work, which self-hosts Canvas for its faculty and students. I'm using Fetch API (but have tried with other ajax methods too). However, anytime I try to GET something I just get an empty response back. Body is null and statusText is empty.
The thing that's weird is if I access the URL directly in my browser, I see the JSON just fine. But when I Fetch with the exact same URL I just see an empty response. For example, in the browser https://canvas.uchicago.edu/api/v1/users/self shows me my ID, name, sortable name, etc. Hitting that with a GET fetch gives just an empty response.
Status of the call is 200 and I'm not getting any CORS errors or anything like that, so as far as I can tell it's going through OK.
Any thoughts?
Thanks everybody!!
<SPAN class="keyword token">var</SPAN> token <SPAN class="operator token">=</SPAN> <SPAN class="comment token">// my temp token here</SPAN><BR /><SPAN class="keyword token">var</SPAN> url <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://canvas.uchicago.edu/api/v1/users/self/" rel="nofollow noopener noreferrer">https://canvas.uchicago.edu/api/v1/users/self/</A><SPAN>'</SPAN></SPAN><SPAN class="punctuation token">;</SPAN><BR /><BR /><SPAN class="keyword token">var</SPAN> headers <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Headers</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR />headers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">append</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'X-Requested-With'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'XMLHttpRequest'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR />headers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">append</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Authorization'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="template-string token"><SPAN class="string token">`Bearer </SPAN><SPAN class="interpolation token"><SPAN class="interpolation-punctuation punctuation token">${</SPAN>token<SPAN class="interpolation-punctuation punctuation token">}</SPAN></SPAN><SPAN class="string token">`</SPAN></SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /><BR /><SPAN class="keyword token">var</SPAN> options <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> method<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'GET'</SPAN><SPAN class="punctuation token">,</SPAN><BR /> headers<SPAN class="punctuation token">:</SPAN>headers<SPAN class="punctuation token">,</SPAN><BR /> credentials<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'same-origin'</SPAN><SPAN class="punctuation token">,</SPAN><BR /> mode<SPAN class="punctuation token">:</SPAN><SPAN class="string token">'no-cors'</SPAN><BR /><SPAN class="punctuation token">}</SPAN><BR /><BR /><SPAN class="token function">fetch</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN> options<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>