Polygon API: Cannot save statement contains Vietnamese characters via API

Revision en5, by emeralddd, 2024-05-04 09:17:55

I have recently tried API of Polygon. All things worked correctly until I found I couldn't update statements containing some special Vietnamese characters (eg: ê, ô, ...).

This is my code:

const { default: axios } = require('axios');
const { sha512 } = require('js-sha512');

const a = async () => {
    const key = "xxx";
    const secret = "yyy";

    const date = Math.floor(new Date().getTime() / 1000);
    const rand = 100000 + Math.floor(Math.random() * 900000);

    const apiSig = sha512(`$$${rand}/problem.saveStatement?apiKey=$$${key}&lang=english&legend=ê&problemId=351173&time=${date}#${secret}`);

    const req = await axios.post(`https://polygon.codeforces.com/api/problem.saveStatement?apiKey=${key}&lang=english&legend=${encodeURIComponent('ê')}&problemId=351173&time=${date}&apiSig=${rand}${apiSig}`);

    return req.data;
}

a();

Nodejs 20.11.1 Axios 1.6.8

After I had sent the request, I got the error message: "Incorrect signature". Everything worked normally when I removed all the special Vietnamese characters.

Anyone can help me with this issue, pls!

Tags polygon, api, polygon api

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English emeralddd 2024-05-04 09:17:55 0 (published)
en4 English emeralddd 2024-05-04 09:12:59 25
en3 English emeralddd 2024-05-04 09:11:07 2 Tiny change: ' 20.11.1\n\nAxios 1.' -> ' 20.11.1\nAxios 1.'
en2 English emeralddd 2024-05-04 09:10:28 33 Tiny change: 'n~~~~~\n\nAfter ' -> 'n~~~~~\n\nNodejs 20.11.1\n\nAxios 1.6.8\n\nAfter '
en1 English emeralddd 2024-05-04 09:09:18 1166 Initial revision (saved to drafts)