A question regarding my next plugin

  • You can pass in a user-agent field into the request options

            url: 'http://api.discogs.com/database/search?catno=' + discogNum + '&type=release&per_page=1',
            headers: {
                'User-Agent': 'request'

  • @psychobunny

    Found that through julians Github plugin, so I did that, and now I've got

    error: TypeError: Cannot read property 'statusCode' of undefined
    at Request._callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:76:21)
    at self.callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:123:22)
    at Request.emit (events.js:95:17)
    at Request.self._buildRequest (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:355:39)
    at Request.init (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:533:10)
    at new Request (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:99:8)
    at request (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/index.js:54:11)
    at Function.request.get (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/index.js:127:27)
    at getDiscog (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:70:13)
    at async.map.appModule.render.discoginfo (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:38:13)

    which is

        }, function(err, response, body) {
        if (response.statusCode === 200) {
            callback(null, JSON.parse(body));
  • NodeBB Admin

    Check for err

    }, function(err, response, body) {
    if (!err && response.statusCode === 200) {
        callback(null, JSON.parse(body));
    } else {
        console.log(err, response);

  • @baris NodeBB crashes when I try to access the category the topic is posted in. Nothing in the console.

    EDIT: Sorry missed !err, will report back shortly. 😆

    [Error: Invalid protocol: null] undefined

  • NodeBB Admin

    Haha no idea maybe they want https?

  • @baris That was exactly the case, earlier on I'd removed http to check something and not added it back. Ok, the page loads now, with the partial tpl file. But no data, so I'm assuming doing {results.title} and {results.year} etc (as depicted by the API), isn't how I pull the info?

  • NodeBB Admin

    Yeah look at the data returned when you go to that page then you can use the data in the template with {data.title} as usual.

  • Right, narrowed it down somewhat.

    returnData { uri: undefined,
    thumbnail: undefined,
    catno: undefined,
    title: undefined,
    style: undefined,
    label: undefined,
    year: undefined }

  • Now we're all awake again, I'm going to have another stab at this if anyone has any suggestions... 🙂

  • How's it going?

  • @psychobunny About where my last post is, I couldn't work out why it doesn't seem to be connecting to the api, or if it does, I just don't know how to pull the data that I'm looking for. I know what I want, and I think I know how to get it, but the only way it doesn't crash the plugin, it gives me the undefined error above. 😢

    Basically this is the json output of what I wish to target.

    "pagination": {
        "per_page": 1,
        "items": 14256,
        "page": 1,
        "urls": {
            "last": "http://api.discogs.com/database/search?per_page=1&type=release&catno=VSN018&page=14256&f=json",
            "next": "http://api.discogs.com/database/search?per_page=1&type=release&catno=VSN018&page=2&f=json"
        "pages": 14256
    "results": [
            "style": [
                "Drum n Bass"
            "thumb": "http://api.discogs.com/image/R-90-5844720-1404286626-1507.jpeg",
            "format": [
                "45 RPM",
            "country": "Netherlands",
            "title": "Noisia - Purpose EP",
            "uri": "/Noisia-Purpose-EP/release/5844720",
            "community": {
                "have": 17,
                "want": 27
            "label": [
                "Vision Recordings"
            "catno": "VSN018",
            "year": "2014",
            "genre": [
            "resource_url": "http://api.discogs.com/releases/5844720",
            "type": "release",
            "id": 5844720


    returnData = {
                    results: {
                        uri: results.uri,
                        thumbnail: results.thumb,
                        catno: results.catno,
                        title: results.title,
                        style: results.style,
                        label: results.label,
                        year: results.year

    Returns undefined for everything, so I'd assume it doesn't connect. 🙂

  • GNU/Linux Admin

    @a_5mith, results in that returned data set is an Array, so you'll have to iterate through it (or cheap out and just look at the first array index):

    returnData = {
        results: {
            uri: results[0].uri,
            thumbnail: results[0].thumb,
            catno: results[0].catno,
            title: results[0].title,
            style: results[0].style,
            label: results[0].label,
            year: results[0].year

    ... maybe?

    Edit: Wow, that was fast.

  • @julian

    Edit: Wow, that was fast.

    Pushbullet for Firefox opens the tab automatically. 😆

    Will give it a go. 🙂

  • Right, Birthdays over now (after 3 days) and I'm back on Plugin Development. 😆

    SyntaxError: Unexpected token
    at Object.parse (native)
    at Request._callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:84:33)
    at Request.self.callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:123:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:1047:14)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:998:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:929:16
    at process._tickDomainCallback (node.js:463:13)

    84:33 corresponds to the parse in callback(null, JSON.parse(body)),

  • Means your JSON is malformed, perhaps do a console.log(body) and try and find if you're missing a comma somewhere (maybe http://jsonlint.com may help you in that respect)

    EDIT: birthday? yours? 😛 🍰

  • @psychobunny Yeah, turned 23 on the 25th. 😆 🎂

    Right, after a few hours, I'd accidently Ctrl K'd a line out that defines the results var... :shakes head:

    I'm now getting output back from discogs, however, it's definitely not right, I've thrown it into a pastebin.

  • Right, progress, I've got the pagination part

     {"pagination": {"per_page": 50, "items": 0, "page": 1, "urls": {}                                                                                                                     , "pages": 1}, "results": []}

    However results is just [], which is the bit I need. 😆

    Ok, back at undefined, so would appear @julian's snippet didn't work for me. 😞

  • So, I left this for a week or two, just come back to it to see if I could get it working, checked my console.log and what do you know, I have progress, I now have the output that I need (albeit all of it, not just what I specified)

    {"pagination": {"per_page": 1, "items": 1, "page": 1, "urls": {}, "pages": 1}, "results": [{"style": ["Breaks", "Electro", "Drum n Bass"], "thumb": "http://api.discogs.com/image/R-90-3071347-1314359516.jpeg", "format": ["CDr", "Album", "Promo"], "country": "UK", "barcode": [], "uri": "/Noisia-Split-The-Atom/release/3071347", "community": {"have": 12, "want": 10}, "label": ["Vision Recordings"], "catno": "VSNCD001P", "year": "2010", "genre": ["Electronic"], "title": "Noisia - Split The Atom", "resource_url": "http://api.discogs.com/releases/3071347", "type": "release", "id": 3071347}]}

    So my question now is what would I use to get this into the template file?

    I've done {results.catno} and used @julian's earlier method of looping through, but neither works. Any ideas?

    I only need bits of the info inside results. Not the pagination bit.

  • GNU/Linux Admin

                "Drum n Bass"
                "Vision Recordings"
             "title":"Noisia - Split The Atom",

    Just making it look nice 🙂

    You'll need to work with the values in the results hash then... how come you want the data in the template file, and aren't using a hook to modify the post text like the other plugins?

  • @julian It's a card like the Github Plugin that's used here.

    Users enters a category number, and it gets filled out like this:


Suggested Topics

| | | |