Create Article using apple-news api problems

Hello, I am stuck at the same point my code and can't figure out what is wrong with it. Can someone take a look an advise on what might be the problem. I am writing a curl post request using PHP. I can successfully connect to get information about my channel but can't post an article there.

Error I am getting is

( [code] => MISSING [keyPath] => Array ( [0] => article.json ) )


JSON FILE

{
  "title": "Article Title",
   "version": "1.5",
  "identifier": "testArticle",
  "language": "en",
  "layout": {
    "columns": 10,
    "width": 1024,
    "margin": 85,
    "gutter": 20
  },
  "documentStyle": {
    "backgroundColor": "#F5F9FB"
  },
  "components": [],
  "textStyles": {},
  "componentLayouts": {},
  "componentStyles": {},
  "componentTextStyles": {}
}

CODE

<?php
//set the timezone
date_default_timezone_set('UTC');


//get json to be sent
$data = json_encode('article.json');

$Content_Type='Content-Type: multipart/form-data; boundary=--535e329ca936f79a19ac9a251f7d48f7';

//set variables
$http_method = 'POST';
$date = gmdate('Y-m-d\TH:i:s\Z');
$key = 'xxxx';
$url = 'https://news-api.apple.com/channels/***/articles';
$secret = '***';

//cannonical request
$canonical_request = $http_method . $url . $date. 'multipart/form-data; boundary=--535e329ca936f79a19ac9a251f7d48f7' . $data;

//Signature
$secretKey = base64_decode($secret);
$hash = hash_hmac('sha256', $canonical_request, $secretKey, true);
$signature = base64_encode($hash);

$authHeader = "HHMAC; key=$key; signature=$signature; date=$date;";
$headers = array();

$headers[] = "Authorization: $authHeader";
$headers[] = "Accept: application/json";
$headers[] = "Content-Disposition: form-data; filename=article.json; size=".strlen($data);
$headers[] = $Content_Type;

//curl options
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);

//get result
$server_output = curl_exec ($ch);
curl_close ($ch);
print_r(json_decode($server_output));
?>

Replies

I am actually having the same problem. And in your case, could you please try


$data = file_get_contents('article.json');