PDA

View Full Version : How to get the thread URL from a nodeid?


ndoktoruser
02-08-2016, 03:48 PM
Let's suppose I have a node id (the integer value) which corresponds to a thread. How do I get the URL?

Replicant
02-09-2016, 12:34 AM
You can get to the threads by nodeid using the www.example.com/forum/node/1234 where 1234 is the nodeid. Is that what you are looking for or are you looking for API?

from the command line ---- curl http://www.vbulletin.com/forum/ajax/api/route/getAbsoluteNodeUrl?nodeid=54756
or javascript --- $.ajax({
url: 'http://www.vbulletin.com/forum/ajax/api/route/getAbsoluteNodeUrl',
type: "POST",
dataType: 'json',
data: {
nodeid:'547'
},
success: function(response) {
if (response){
alert(response);
}
}
});


The ajax method is hit or miss. On VB 5.2, I don't know why, but if a user is logged in, this js throws an error, but for guests, works as expected.

You can also call the API in the templates using {vb:data}

ndoktoruser
02-09-2016, 01:31 PM
Once and again, thank you very much!

I did as you said using curl:

$curl = curl_init('http://my.page/ajax/api/route/getAbsoluteNodeUrl');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'nodeid=' . $id);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$url = curl_exec($curl);
curl_close($curl);

It was exactly what I needed.

Replicant
02-10-2016, 01:32 PM
Once and again, thank you very much!

I did as you said using curl:

$curl = curl_init('http://my.page/ajax/api/route/getAbsoluteNodeUrl');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'nodeid=' . $id);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$url = curl_exec($curl);
curl_close($curl);

It was exactly what I needed.

If you are using this in a php script, you can call the api directly in the code also. It'll save an http request and be much faster if you are dealing with several urls. I included a screenshot of the docs for this function.

ndoktoruser
02-15-2016, 03:34 PM
Amazing!

And much simpler now:
$url = vB_Api::instanceInternal('route')->getAbsoluteNodeUrl($id);

excentryk
10-07-2020, 07:18 PM
Hello, sorry for response in old topic - but I have the same problem and don't know how to convert mysite.pl/forum/node1234 to full url to the post. I don't know how to use this getAbsoluteNodeUrl API. Any Tips?

Should create php file example converter.php and put this code in to this file?

I need only working redirection from mysite.pl/forum/node1234 to full url to the post how to do that?