I've read what little I can find about J4 Web Services, but cannot find a working example or get my code to work. The code below should work by all accounts, but I get forbidden on my local machine and not found on our web server. There is no mention of how to be set up to use the API or much else to go on.
Has anyone else tried one of these API calls?
$data = new stdClass();
$data->alias = "my-article";
$data->articletext = "My text";
$data->catid = 11;
$data->language = "*";
$data->metadesc = "metadesc";
$data->metakey = "metakey";
$data->title = "Here's an article";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ' = 'http://localhost/myproject/api/index.php/v1/content/article -d';);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
REturn: (I'm not knowingly using Watchguard anywhere on EC2 or Localhost)
<html>
<body>
<h3> Request denied by WatchGuard HTTP proxy. </h3>
<b> Reason: </b> request protocol version denied line='POST /api/index.php/v1/content/article -d HTTP/1.1\x0d\x0a' <br>
<hr size="1" noshade>
<b> Method: </b> POST <br>
<b> Host: </b> 168.156.127.75 <br>
<b> Path: </b> /api/index.php/v1/content/article <br>
<hr size="1" noshade>
Update: Further attempts yield only errors, so apparently there is far more to getting this to work than just a CURL request. However, the question itself was answered, so thank you for that :). I don't know enough to ask without being too general, so will keep an eye out for someone that does.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
content/articles
, notcontent/article
.content/article
is correct if you're trying to POST content to the database.content/articles
is the GET command to get a list of articles,content/article
will get a single article when GET is used.