I have a question that I feel should be pretty simple to answer, but I cannot find fix anywhere.
I'm querying the Uberchord website for guitar chords (documentation here)
Here is the URL I'm querying:
https://api.uberchord.com/v1/chords?nameLike=${variable}
Where variable is based on what the user types in.
The nameLike lets fuzzy match between the input and the API (For example, the url for an Fmaj7 chord is F_maj7). This works great, but it returns multiple responses. The first response is always the one I want, so I'm trying to just limit the responses to the first one that comes in. So far, I've tried adding a limit or a top filter to the URL to no avail. This is where I'm sure I'm doing something incorrect.
For limit, I've tried:
https://api.uberchord.com/v1/chords?nameLike=${fmaj7}?limit=1
and
https://api.uberchord.com/v1/chords?nameLike=${fmaj7}&limit=1
and for top I've done the same two but just replacing limit with top. The first one returns zero responses, while the second returns all responses.
Any ideas?
It isn't literally "returning multiple responses". It's just returning an array. It ALWAYS returns an array, even if there is only one element. If you only want the first element of that array, then fetch the first element of the array, just like you would with any other array. After you do the JSON decode:
chord = response[0];