Use Syncthing API with PHP

Hello,

I’m trying to put together a simple PHP script

$curl = curl_init("http://example.com:1234/rest/system/config");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-API-Key: abcdefg"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

As result I get “Error 403 - CSRF error”.

What am I missing?

Maybe wrong api key?

thanks for the suggestion but it is correct

I also tried switching to HTTPS which needs

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

because of the self signed certificate - but same result.

if I use this command line it works :thinking:

curl -H "X-API-Key: abcdefg" http://example.com:1234/rest/system/config

I guess I’ll do this as a bash script then :man_shrugging:

Php gonna php