4

EDIT: Solved, posted details below as answer... Pretty stupid user error

I'm trying to write simple plugin for SteelSeries Gamesense to display currently playing song from iTunes in GameDAC screen. Basically the engine works via provided server listening to post requests with JSON body. I've been trying to get my request working for quite a while but with no go.

I tested request on Postman and it should be working as intended, so the problem is somewhere in syntax probably.

const axios = require('axios');


const coreProps = require(process.env.ProgramData + '/SteelSeries/SteelSeries Engine 3/coreProps.json');
const url = JSON.stringify(coreProps['address']);

axios.defaults.baseURL = 'http://' + url.replace(/"/g,'');
axios.defaults.headers['post'] = {'Content-Type': 'application/json'};

console.log(axios.defaults.headers);

function bind_itunes() {

    const data = {
        "game": "ITUNES",
        "event": "NOWPLAYING",
        "handlers": [
            {
                "device-type": "screened",
                "zone": "one",
                "mode": "screen",
                "datas": [
                    {
                        "has-text": true,
                        "context-frame-key": "songname"
                    }
                ]
            }
        ]
    };

    axios.post('game_event', JSON.stringify(data))
        .then((res) => {
            console.log(res)
        }).catch((error) => {
        console.error(error)
    })
}

bind_itunes();

Code fails with long error block from Axios with error

"data: { error: 'passed value not string or JSON object' } }"

full error log (pastebin since it's quite long): https://pastebin.com/aLguKQ2C

Postman screenshot

enter image description here

5
  • Why are you using JSON.stringify() on a URL? Can you share some screenshots of it working in Postman? Commented Jun 7, 2019 at 1:38
  • FYI, the Axios default content type is already JSON. You can just use axios.post('game_event', data) Commented Jun 7, 2019 at 1:42
  • Forgot to mention @Phil, got same problem without stringify() and decided to add it there. Postman screenshot: imgur.com/9gEef9n . The underscore shouldn't matter since it's only chosen identifier for future when there will be text sent via that event bound to Engine. Resorting to default headers also has same result Commented Jun 7, 2019 at 1:47
  • 1
    Postman is posting to bind_game_event but your code is posting to game_event so they're definitely not the same Commented Jun 7, 2019 at 2:21
  • Yah... Noticed myself a second ago. Thanks for answer anyways, next time I'll make extra steps to eliminate typos like this. Feel free to post as answer so I can flag as solved. Commented Jun 7, 2019 at 2:25

2 Answers 2

3

Next time before asking question, I'll also make sure to triple check the API endpoints.

As seen when comparing the screenshot and code, I'm polling on wrong endpoint (game_event instead of bind_game_event), which quite obviously causes request to be bad.

Fixed the problem after hours and hours of wondering.

Thanks for assistance to everybody who tried and sorry to bother.

Sign up to request clarification or add additional context in comments.

Comments

2

I would have suggested the same as @Phil: not to stringify your payload when using axios.post. The examples in the documentation of Axios might be useful: https://github.com/axios/axios. I took a look at your screenshot, it seems that you got a successful response with a status code of 200. Are you still having an issue or is the response to your request different?

1 Comment

Using Postman I get the successful response, but when using code above in node run application I'm still getting statusCode 400 while the request is the exact same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.