InfoBlock Posted March 23 Share Posted March 23 Hello everyone, I'm trying to do an "GET" Request on the TruckersMP API to get the amount of Members in an VTC But I have no idea on how to do that so... How can I do an "GET" Request on the TruckersMP API to get the amount of Members in an VTC and display it on my website? Need an way to add it to HTML! Link to comment Share on other sites More sharing options...
CJMAXiK Posted March 29 Share Posted March 29 8 hours ago, InfoBlock said: Perfect, no one can help me... You just need to read TruckersMP API documentation - https://stats.truckersmp.com/api#vtc_members. TruckersMP provides an API, other stuff like processing and templating is up to you. Developer @ VTC.World Just Monika Link to comment Share on other sites More sharing options...
InfoBlock Posted March 29 Author Share Posted March 29 14 hours ago, CJMAXiK said: You just need to read TruckersMP API documentation - https://stats.truckersmp.com/api#vtc_members. TruckersMP provides an API, other stuff like processing and templating is up to you. Well I have no idea how to do an API Request I've never worked with API's on a Website Link to comment Share on other sites More sharing options...
[TPH] Nicz Posted April 11 Share Posted April 11 Sounds good if you will follow the documentation it's simple to get. Link to comment Share on other sites More sharing options...
Bobita Carciumaru Posted April 27 Share Posted April 27 did you try to google something? or some tutorials? Link to comment Share on other sites More sharing options...
Trucker_Bean Posted May 1 Share Posted May 1 Hello, If you want to add data from the API to your web application, you can use this. If the aforementioned isn't suitable, you can use tutorials like this to aid you in creating what you desire. Please note that the above are not solutions and are simply to aid you in the process of creating what you need. Kind Regards, Bean Link to comment Share on other sites More sharing options...
InfoBlock Posted May 4 Author Share Posted May 4 I need an way to do it in JavaScript not in PHP, I have 0 PHP experience! Link to comment Share on other sites More sharing options...
CJMAXiK Posted May 4 Share Posted May 4 3 hours ago, InfoBlock said: I need an way to do it in JavaScript not in PHP, I have 0 PHP experience! There are plenty of public API usage tutorials on Internet, I do not understand why we have to make the thing specifically for you? Developer @ VTC.World Just Monika Link to comment Share on other sites More sharing options...
InfoBlock Posted May 5 Author Share Posted May 5 On 5/4/2022 at 11:21 AM, CJMAXiK said: There are plenty of public API usage tutorials on Internet, I do not understand why we have to make the thing specifically for you? Some real examples of an API Request via JavaScript would be good not just for example GET /player/{id} Link to comment Share on other sites More sharing options...
InfoBlock Posted May 5 Author Share Posted May 5 On 5/1/2022 at 11:47 PM, Trucker_Bean said: Hello, If you want to add data from the API to your web application, you can use this. If the aforementioned isn't suitable, you can use tutorials like this to aid you in creating what you desire. Please note that the above are not solutions and are simply to aid you in the process of creating what you need. Kind Regards, Bean The second tutorial kinda helps me out but I keep getting an failed to fetch error Link to comment Share on other sites More sharing options...
Trucker_Bean Posted May 5 Share Posted May 5 3 hours ago, InfoBlock said: The second tutorial kinda helps me out but I keep getting an failed to fetch error If you're getting errors, there're plenty of platforms for you to reach out to and get help. Link to comment Share on other sites More sharing options...
InfoBlock Posted May 7 Author Share Posted May 7 On 5/5/2022 at 11:07 PM, Trucker_Bean said: If you're getting errors, there're plenty of platforms for you to reach out to and get help. I've been looking for hours and found absolutely nothing, even looked at some Discord Bots doing API Requests to know how it works as I only had to make it available for Web use then, still nothing Link to comment Share on other sites More sharing options...
Trucker_Bean Posted May 7 Share Posted May 7 1 hour ago, InfoBlock said: I've been looking for hours and found absolutely nothing, even looked at some Discord Bots doing API Requests to know how it works as I only had to make it available for Web use then, still nothing For example, this is how I'd create a request in python. import requests import json query = requests.get('url') result = query.json() You can use the API documentation should you require more help or want to know what data you can receive from endpoints etc... While I understand you cannot find a solution to work for you, you shouldn't expect someone to spoon feed you a solution. If you go forward with this mindset, you'll not learn for yourself. A key part of programming is problem-solving and having the ability to overcome any roadblocks you may encounter. I hope this helps. Kind Regards, Bean Link to comment Share on other sites More sharing options...
InfoBlock Posted May 7 Author Share Posted May 7 5 hours ago, Trucker_Bean said: For example, this is how I'd create a request in python. import requests import json query = requests.get('url') result = query.json() You can use the API documentation should you require more help or want to know what data you can receive from endpoints etc... While I understand you cannot find a solution to work for you, you shouldn't expect someone to spoon feed you a solution. If you go forward with this mindset, you'll not learn for yourself. A key part of programming is problem-solving and having the ability to overcome any roadblocks you may encounter. I hope this helps. Kind Regards, Bean Well I found some useful stuff on the internet but the requests keep resulting in an "Failed to fetch" which I can't seem to get fixed.. Link to comment Share on other sites More sharing options...
Trucker_Bean Posted May 8 Share Posted May 8 Well, I'm glad you've managed to find something on the internet. On 5/7/2022 at 8:46 AM, InfoBlock said: but the requests keep resulting in an "Failed to fetch" which I can't seem to get fixed. While examples on the internet may work for their intended purpose, they may not work for your intended purpose. Therefore, you'd have to alter the pre-provided examples to work with the API and what you require. Link to comment Share on other sites More sharing options...
InfoBlock Posted May 11 Author Share Posted May 11 On 5/8/2022 at 9:19 PM, Trucker_Bean said: Well, I'm glad you've managed to find something on the internet. While examples on the internet may work for their intended purpose, they may not work for your intended purpose. Therefore, you'd have to alter the pre-provided examples to work with the API and what you require. I can't work with the given examples as those aren't real code examples! It is literally just GET [Some API Link Request] and then shows the result underneath Link to comment Share on other sites More sharing options...
Trucker_Bean Posted May 11 Share Posted May 11 Isn't that what you want? Once you've got the result of your request, you can use that how you like. Link to comment Share on other sites More sharing options...
InfoBlock Posted May 14 Author Share Posted May 14 On 5/11/2022 at 4:02 AM, Trucker_Bean said: Isn't that what you want? Once you've got the result of your request, you can use that how you like. No? I need some real examples on how to do the GET request! Everything I tried resulted in "Failed to fetch" Link to comment Share on other sites More sharing options...
Community Manager Coolio85 Posted May 15 Community Manager Share Posted May 15 @InfoBlock Would you be able to post the code you are trying to run then someone might be able to help you? TruckersMP Community Manager Link to comment Share on other sites More sharing options...
InfoBlock Posted May 15 Author Share Posted May 15 (edited) 2 hours ago, Coolio85 said: @InfoBlock Would you be able to post the code you are trying to run then someone might be able to help you? let url = 'https://api.truckersmp.com/v2/player/2515622'; fetch(url).then(function(response) { return response.json(); }).then(function(data) { console.log(data); }).catch(function() { console.log("Catch Log"); }); Would've tried it with PHP but my Websites run via Github and on Github PHP doesn't work at all Edited May 15 by InfoBlock Added the Code Link to comment Share on other sites More sharing options...
Recommended Posts