Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Try to make a request HTTPS based on CURL example

Hi! I'm trying to make a simple request with fetch but I have some difficulty to have a response.

I try to convert this example create for CURL : 

curl -v -u 1971800d4d82861d8f2c1651fea4d212:api_token \
	-H "Content-Type: application/json" \
	-d '{"domain":"url.com"}' \
	-X POST https://www.toggl.com/api/v9/me/cors

And my version for the companion app :

const headers = {
         'Accept': 'application/json',
         'Auth' :  {
            'user': '87129847189471242ennenbe21test',
            'pass': 'api_token'
          }
 }
const url = 'https://www.toggl.com/api/v8/me';
const opts = {headers: headers, 'Method' : 'POST'};

function queryDataPrint() {
  fetch(url).then(function (response) {
      response.json()
      .then(function(data) {
        if (peerSocket.readyState === peerSocket.OPEN) {
         console.log(JSON.stringify(data));
        }
      });
  })
  .catch(function (err) {
    console.log("Error fetching data : " + err);
  });
}

A little idea of where I can make my mistake? Thank in advance

Best Answer
0 Votes
1 REPLY 1

Looks like you're pretty much there, you've just omitted to pass the options into the fetch().

 

 

fetch(url, opts).then(

 

 

Best Answer
0 Votes