Unable to make REST calls to my CPanel plugin

jwineman

Registered
Nov 19, 2015
4
0
1
San Francisco
cPanel Access Level
Reseller Owner
So I have this javascript:
Code:
import fetch from 'isomorphic-fetch';

export default function proxyReqeust(method, url, body) {
    var headers = new Headers();
    headers.append('host_key', '0c919912bc9e8fac8e24bf65f76ce34a');

    var myInit = { method: method,
        headers: headers,
        body: JSON.stringify(body)};

    //TODO: clean up this hack
    var myurl = document.URL.substr(0,document.URL.lastIndexOf('/'));
    myurl = myurl.replace("index.html/#","index.php");
    return fetch('
https://cpanel.domain:2083/cpsess5843135714/frontend/paper_lantern/[...]/index.php
',myInit);
When I try to make a POST request to that URL I get the Cpanel login page. If I hit it in my browser it shows up fine so I thought maybe I could GET it but GET requests failed too. At first I was passing the relative url which I assume failed cause I was missing the CPanel session but now I'm passing in the absolute URL with the CPanel session and it still fails. What am I doing wrong?
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,219
463
Okay the issue was my request body was malformed.
I am happy to see you were able to address the issue. Thank you for updating us with the outcome.