Reputation: 71
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
Upvotes: 4
Views: 4101
Reputation: 71
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.
Upvotes: 3
Reputation: 1178
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?
Upvotes: 2