Calling REST API with Auth, CSRF Token not working


I am using PHP to call the authentication with admin/admin , so I can use all the REST model services available. However I encounter issue when retrieving the csrf-token from the response.

Below is my code:

$url = ‹ http://localhost:8080/axelor-erp-latest/login.jsp ›;

$params = [
‹ username › => ‹ admin ›,
‹ password › => ‹ admin ›
$checktoken = AxelorApi::callAPI(‹ POST ›, $url, $params);

I able to login with above POST action, and get the cookie from the headers, however it is not working when I pass it to Employee REST endpoint, it just show 302 which is unauthenticated.

below is my Employee API:

$url = 'http://localhost:8080/axelor-erp-latest/ws/rest/';

$header = [
     'X-CSRF-Token' => '3d804e4608864eb5a0d930f798cc6d2a',

I also tried with below syntax:

$header = [
    'Cookie' => 'CSRF-TOKEN=3d804e4608864eb5a0d930f798cc6d2a'

But still not working. May I know is there any sample out there for this? Especially how to retrieve the cookies and pass it to HTTP header.

But when I tried it with Postman, and use the CSRF-TOKEN and JSESSIONID as the header, they are working. How Can I make it work from my server?



Maybe you will find interesting to use n8n.
But you will have info to use the HTTP Request with cookies

Tell me if you don’t understand and need more help