Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • [SNIPPET] [API] Item Name -> ID & Runelite Price Lookup


    TheCloakdOne
     Share

    Recommended Posts

    As part of another project i needed a nicer way of handling Item names -> ID's without bloating out scripts with bulky json files so built an API to provide this information to anyone who needs it. API is built in Golang & on a highly available platform so shouldnt ever go down. Feel free to use :) if there is enough traffic ill add a redis cache to speed it up further.

    The API will take an String input (item name or ID) and return the current Runelite Buy & Sell prices along with the Item ID. If no item can be found item id will be 0.

    Site now also supports HTTP traffic (swap HTTP for HTTPS in examples)

     

    Examples:

    Glory:
    http://mule.cloakd.co.uk/lookup/items/name?name=Amulet%20of%20glory(6)
    http://mule.cloakd.co.uk/lookup/items/id?id=11978
    
    Dragon Scim:
    http://mule.cloakd.co.uk/lookup/items/name?name=Dragon%20scimitar
    http://mule.cloakd.co.uk/lookup/items/id?id=4587
    
    Bucket:
    http://mule.cloakd.co.uk/lookup/items/name?name=Bucket
    http://mule.cloakd.co.uk/lookup/items/id?id=1925

     

    Response:

    {
    "id": 11978,
    "name": "Amulet of glory(6)",
    "buy_price": 11999,
    "sell_price": 11999
    }

     

    Code Snippets

     

    Response Class:

    public class ItemResponse {
       public int id = -1;
       public String name = "";
       public int buy_price = 0;
       public int sell_price = 0;
    }

     

    Example Function:

    function ItemResponse getItem(string name) {
            String encName = "";
            try {
                encName = URLEncoder.encode(name, StandardCharsets.UTF_8.toString());
            } catch (UnsupportedEncodingException e) {
                return null;
            }
    
            String resp = this.getJson("http://mule.cloakd.co.uk", "/lookup/items/name?name=" + encName);
            if (resp == null)
                return null;
    
            return gson.fromJson(resp, ItemResponse.class);
    }

     

    function ItemResponse getItem(int id) {
    	String resp = this.getJson("http://mule.cloakd.co.uk", "/lookup/items/id?id=" + id);
            if (resp == null)
                return null;
    
            return gson.fromJson(resp, ItemResponse.class);
    }

     

    Example JSON Call:

    public String getJson(String baseURL, String targetURL) {
            MethodProvider.logInfo("GET - " + baseURL + targetURL);
            HttpURLConnection connection = null;
    
            try {
                URL url = new URL(baseURL + targetURL);
    
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.setRequestProperty("Content-Type",
                        "application/json; utf-8");
                connection.setRequestProperty("Accept", "application/json");
                connection.setUseCaches(false);
                connection.setDoOutput(true);
    
                int code = connection.getResponseCode();
                if (code >= 400) {
                    MethodProvider.logInfo("Network HTTP error: " + code);
                    return null;
                }
    
                if (code == 204) {
                    MethodProvider.logInfo("Network HTTP No Content: " + code);
                    return null;
                }
    
                //Get Response
                InputStream is = connection.getInputStream();
                BufferedReader rd = new BufferedReader(new InputStreamReader(is));
                StringBuilder response = new StringBuilder(); // or StringBuffer if Java version 5+
                String line;
                while ((line = rd.readLine()) != null) {
                    response.append(line);
                    response.append('\r');
                }
                rd.close();
                return response.toString();
            } catch (Exception e) {
                MethodProvider.logInfo("getJson Err: " + e.getMessage());
                e.printStackTrace();
                return null;
            } finally {
                if (connection != null) {
                    connection.disconnect();
                }
            }
        }

     

    Edited by TheCloakdOne
    Link to comment
    Share on other sites

    • TheCloakdOne changed the title to [SNIPPET] Item ID & Runelite Price Lookup
    • TheCloakdOne changed the title to [SNIPPET] [API] Item Name -> ID & Runelite Price Lookup
    • 2 weeks later...

    Now updated to support ID also if needed:

     

    function ItemResponse getItem(int id) {
            String resp = this.getJson("http://mule.cloakd.co.uk", "/lookup/items/id?id=" + id);
            if (resp == null)
                return null;
    
            return gson.fromJson(resp, ItemResponse.class);
    }

     

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.