How to make a request without 403 Forbidden error

Hi,
I try to make some requests to musicbrainz db from my web server but I always have errors in return.

I’m not a programmer (I realy think now that I’m very very bad …) because I don’t undertstand how to make juste one request and it’s going to make me crazy !

I try in a PHP file :

$artist = “ZZTop”;
$song_title = “It’s only Love”;
$mb_query = ‘https://www.musicbrainz.org/ws/2/recording?query="’.$song_title.’"’.’ AND artist:"’.$artist.’"’;
$xml = simplexml_load_file($mb_query);
$releasedate = $xml->{‘recording-list’}->recording[0]->{‘release-list’}->release[0]->date;
echo "Date : ".$releasedate;

Answer :
Warning: simplexml_load_file(https://www.musicbrainz.org/ws/2/recording?query=“It’s%20only%20Love”%20AND%20artist:“ZZTop”): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

$url = “http://musicbrainz.org/ws/2/artist/8bfac288-ccc5-448d-9573-c33ea2aa5c30?inc=release-groups”;
$xml = simplexml_load_file($url);

$releasegrouplist = “release-group-list”;
$releasegroup = “release-group”;

$i = “0”;
for ($i = 0; $i <= 1; $i++)
{
echo "release: " . $xml->artist->{‘release-group-list’}->{‘release-group’}[$i]->title;
}

Answer :
Warning: simplexml_load_file(http://musicbrainz.org/ws/2/artist/8bfac288-ccc5-448d-9573-c33ea2aa5c30?inc=release-groups): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

Sometimes people speak about “User-Agent” ? I didtn’t find anything interesting on it and how to use it !
Is it possible to find some exemples in php to help me understand how to use it ?

I just want to do requests with “barcode” and have xml answer with release date, songs titles, genre and cover !

Thank’s in advance for your help !

You need to identify your application in some way, generic php script will be ignored and give you a 403.
You most likely need to split this in to 2 tasks, download the response over http and parse the output.
using simpeXml_load_file it does not look like you can change the http headers so you will need another way of downloading the file first.

As there are occasional “bad actors” that do some stupid things with the web service there is a policy that each client should identify themselves by using http client headers so they know who is to blame.

1 Like

Thank’s “dns_server” for your reply.
Now I use the PHP ini_set(‘user_agent’, ‘MyApp/1.0 (name@domaine.com)’) function to identify my application juste before the request with the simpeXml_load_file() and it’s seems to work with the second request in my previous post.

I really dont know if it’s a good solution or not, but I’m going to use it to make tests !

1 Like

I am having this issue and i cant resolve it, does anyone have a snipple with an example?

even when i hard code the artist name i still get error. is there some other request i have to send?

           string uri = string.Format("http://musicbrainz.org/ws/2/artist/?type=xml&name=Sean+Paul", name);
            XPathDocument doc = new XPathDocument(uri);
            XPathNavigator nav = doc.CreateNavigator();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
            nsmgr.AddNamespace("mb", "http://musicbrainz.org/ns/mmd-2.0#");
            string xpath = string.Format("//mb:artist[mb:name=\"{0}\"]", name); 
            XPathNodeIterator ni = nav.Select(xpath, nsmgr);
            if (!ni.MoveNext()) return null;
            XPathNavigator current = ni.Current;
            return current.GetAttribute("id", nsmgr.DefaultNamespace);

Hi @cutsdbz,
Please don’t use unrelated threads to ask your question - if you have a problem with something in the API please feel free to open a new thread.

You’ve not said exactly what your issue is, but I assume that you’re unable to perform an artist search. Did you try your query in a web browser to see if it gives you the expected result.

You should look at the documentation to find out how to do a search: https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2/Search

You probably want something like this:
http://musicbrainz.org/ws/2/artist/?query=Sean+Paul