Rooyca / obsidian-api-request

Obsidian plugin that allows you to make HTTP requests and display responses directly in the document, in codeblocks, or store them in localStorage.
https://rooyca.github.io/obsidian-api-request/
MIT License
100 stars 5 forks source link

Error: Unexpected token '<', " #7

Closed tlwt closed 5 months ago

tlwt commented 5 months ago

I try to use the MonicaHQ API to get contact details. It requires a Auth-Token and via curl things work fine:

CURL -H "Authorization: Bearer secretKeyCodeReallyLong" https://app.monicahq.com/api

but via plugin I get the above mentioned message Error: Unexpected token '<', "

     ```req
     url: https://monica.witt.eu.org/api/activities
     header: {"Authorization": "Bearer secretKeyCodeReallyLong" }


I think the bearer token is not send correctly, because then the API page will try to redirect you to the main page.

P.S: Awesome plugin - really looking forward to getting this going. 
Rooyca commented 5 months ago

Hello, this has to do with the type of response. If you add response-type: txt you will see that you get an HTML form and the < is for <!DOCTYPE>.

But regarding your problem I have been trying everything, but nothing seems to work, I even tried using cookies instead of Bearer Token but that didn't work either.

I'll keep looking to see if we can solve this problem. Have a nice day.

PS: I'm glad you liked the plugin.

Rooyca commented 5 months ago

I think I solved it... There were two problems:

  1. the s was missing in headers.
  2. The GET requests were not using HEADERS

I already uploaded the new version to Obsidian for you to update and test if it works for you.

tlwt commented 5 months ago

Awesome! Thanks for the quick resolution. It works for me now.