Rooyca / obsidian-api-request

Obsidian plugin that allows you to make requests to API's and receive responses in codeblocks or store them in localStorage.
https://rooyca.github.io/obsidian-api-request/
MIT License
78 stars 4 forks source link

Mixing up frontmatter values? #18

Closed sij-ai closed 1 month ago

sij-ai commented 1 month ago

Describe the bug It seems the extension is mixing up frontmatter variables/values. The following in Obsidian:

---
date: "2024-04-17"
zip: "97401"
banner: "![[obsidian/banners/2024-04-17.jpeg]]"
tags:
  - daily-note
---
#  [[2024-04-16 Tuesday|← ]]  Wednesday April 17th, 2024 [[2024-04-18 Thursday| →]]

` ` `req
url: https://api.lone.blue/note/weather/{{this.date}}?zip={{this.zip}}&api_key=sk-REDACTED
headers: { "Authorization": "Bearer sk-REDACTED" }
response-type: md
` ` `

results in the following API request: "GET /note/weather/2024-04-17?zip=2024-04-17&api_key=sk-REDACTED HTTP/1.1" 404 Not Found

As you can see, it's reusing the date instead of sourcing the zip. This happens regardless of whether the date is a string or a date object, or whether the zip is a string or a number.

To Reproduce See above.

Expected behavior "GET /note/weather/2024-04-17?zip=97401&api_key=sk-REDACTED HTTP/1.1" 204 OK

Desktop (please complete the following information):

sij-ai commented 1 month ago

I came up with a silly workaround that I thought might be helpful in tracing the source of the issue:

url: https://api.lone.blue/note/weather/{{this.date}}?dummy=true;zip={{this.zip}}
headers: { "Authorization": "Bearer sk-REDACTED" }
response-type: txt

fixes it. It evidently doesn't like to have query parameters in a row sourced from the frontmatter?

edit -- err, evidently the relevant change that fixes it is actually using a ; instead of &

Rooyca commented 1 month ago

I had harcoded an index, that's why only one variable ({{this.date}}) was displayed.

Could you check if this is fix for you?

Rooyca commented 1 month ago

Hey @iodrift, I would like to know if your problem was solved and if we can close this issue.

sij-ai commented 1 month ago

It's fixed, thank you sir!