Querying MusicBrainz api

https://musicbrainz.org/

I need to find all songs for an artist.
This https://musicbrainz.org/ws/2/artist?query=(John Newman) returns a list of artists but is not an exact search. I only started looking at this today so don’t know much about this API.

MusicBrainz is highly inaccurate, I would suggest Spotify API

What do you mean highly inaccurate?
In testing I have been able to find artists and now trying to find recordings.

Looking at Spotify it doesn’t seem to have an artist lookup (that I can find) and all the demos are not found.

MusizBrainz uses Lucene Syntax for searches, so you can try searching "John Newman" with the quotes, but even that still returned an extra result. It’s just the way the search works. You’ll need to pull up all the results, using as specific a query as you can make, then search through the name field of every artist returned. From there you should cache or otherwise remember the artist’s id field, then query that alone afterward.

According to MusicBrainz, John Newman has 2 albums and no singles in 2019. According to Spotify he has 4 albums and 10 singles in 2019. If you really need to find all songs of the artist, MusicBrainz is probably the last place to look

https://developer.spotify.com/documentation/web-api/reference/search/search/

I added &limit=1 which usually returns the correct artist. To search for songs I use the artist id on the second look up as you suggested.

Note the client I have to do this for specified using musicbrainz so I feel obliged to use this. I may look at Spotify another time.

Have you got a working example?
The documentation is crap.
Actually it looks like you have to sign in which I don’t want the user to do. The app should just run and handle the authorization.

Go to https://developer.spotify.com/dashboard/ and register an app, it’s free and takes literally 30 seconds to obtains API key (don’t check ‘For commercial use’ at development stage). You only need user authorization if you want to access or to control user account.