Unable to make REST calls to my CPanel plugin
So I have this javascript:
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?
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?
-
Hello :) Could you review Guide to API Authentication - Software Development Kit - cPanel Documentation and let us know if the information is helpful? Thank you. 0 -
Okay the issue was my request body was malformed. Sorry to waste your time :) I'm a little confused as to why CPanel didn't let it through but thats okay. 0 -
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.0 -
Just kidding, request body was properly formed. Root cause was the cookie wasn't been set in the header and firefox automatically adds it in without telling me which is why my browser requests worked and code requests failed: Isomorphic-fetch specific fix is to add credentials: 'same-origin' to your init. How do I use window.fetch() with httpOnly cookies 0
Please sign in to leave a comment.
Comments
5 comments