0

Can anyone help me how to do this in javascript if it's possible?

curl \
-H 'Accept: application/json' \
-H 'Client-ID: <client_id>' \
-d'{"channel_id":<channel_id>}' \
-X POST 'https://open-api.trovo.live/openplatform/channels/id'
Seekii
  • 153
  • 2
  • 9
  • Welcome to StackOverflow! Please visit the [Help Center](https://stackoverflow.com/help), take the [tour](https://stackoverflow.com/tour) and read up on [asking good questions](https://stackoverflow.com/help/asking) here. For this problem, you probably want to investigate the [fetch call](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) – Scott Sauyet May 11 '21 at 19:05
  • Possible duplicate of https://stackoverflow.com/questions/25515936/perform-curl-request-in-javascript/25515976 – Kinglish May 11 '21 at 19:07

3 Answers3

0

You can either use a child_process or convert to a fetch(or equivalent)

const exec = require('child_process').exec;

exec('curl ...', function (error, stdout, stderr) {
  // handle result
})
Daniel
  • 34,125
  • 17
  • 102
  • 150
-1

Why you want to use JS.

You can use JQUERY Ajax:

$.ajax({
    url: url,
    dataType: "json",
    type: "POST/GET",
    async: true,
    data: { },
    success: function (data) {
       //code
    },
    error: function (xhr, exception) {
        //console.log err
    }
}); 
-1

This is JS Fetch API:

fetch("https://open-api.trovo.live/openplatform/channels/id", {
  headers: {
    Accept: "application/json",
    "Client-Id": "<client_id>"
  },
 method: "POST"
})
Abhishek Jain
  • 630
  • 6
  • 26