POST events via API error
-
Hi!
I got an issue trying to create events via API. I always get this error:
{"code":"empty_content","message":"Le contenu, le titre et l\u2019extrait sont vides.","data":{"status":400}}
I do set correct Content-Type, so it’s NOT about https://stackoverflow.com/questions/46021570/wordpress-rest-api-acting-like-no-data-is-sent
This is how I post:
$data_string = json_encode($events_json); $curl_post_header = array( "Referer: https://xxx.ch", "Origin: https://xxx.ch", "Content-Type: application/json", "Cache-Control: no-cache", "Pragma: no-cache", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15" ,"Authorization: Basic ".base64_encode($GLOBALS['wpUser'].":".$GLOBALS['wpPass'])."" ,'Content-Length: ' . strlen($data_string) ); printr($curl_post_header,'POST HEADER'); $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_post_header); curl_setopt($curl, CURLOPT_URL,$GLOBALS['update_url']); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS,$data_string); curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_jar']); curl_setopt($curl, CURLOPT_COOKIEJAR, $GLOBALS['cookie_jar']); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_HTTPAUTH , 'CURLAUTH_BASIC'); curl_setopt($curl, CURLOPT_USERPWD, $GLOBALS['wpUser'] . ":" . $GLOBALS['wpPass']); curl_setopt($cn, CURLOPT_VERBOSE,true); $err = @fopen('gigi.txt', 'w'); curl_setopt($curl, CURLOPT_STDERR, $err); $server_output = curl_exec($curl); rewind($err); $xerr = @fread($err, 16 * 4096); fclose($err); printr($xerr,'curl errors'); printr($header,'header','green'); $headerSize = curl_getinfo( $curl , CURLINFO_HEADER_SIZE ); $headerStr = substr( $server_output , 0 , $headerSize ); $bodyStr = substr( $server_output , $headerSize ); // convert headers to array $headers = headersToArray( $headerStr ); curl_close($curl); printr($server_output,'server_output','red'); printr($headers,'returned headers','red');
And this is the JSON that I post:
[ { "date": "2022-09-10T11:00:00", "date_gmt": "2022-09-10T11:00:00", "modified": "2023-01-18T18:10:59", "modified_gmt": "2023-01-18T18:10:59", "status": "future", "type": "sp_event", "title": { "rendered": "Bernex Basket - Lions de Gen\u00e8ve powered by Grand-Saconnex 1" }, "content": { "rendered": "", "protected": false }, "excerpt": { "rendered": null, "protected": false }, "author": "1", "featured_media": 0, "template": "", "format": "league", "leagues": [ 109 ], "seasons": [ 8 ], "venues": [ 148 ], "teams": [ 5391, 6752 ], "main_results": [], "outcome": [], "winner": 5391, "mode": "", "day": "", "minutes": "90", "results": { "0": { "one": "1", "two": "2", "three": "3", "four": "4", "ot": "OT", "points": "T", "outcome": "R\u00e9sultat" }, "5391": { "one": "14", "two": "6", "three": "12", "four": "13", "ot": "", "points": "2", "outcome": "45" }, "6752": { "one": "13", "two": "5", "three": "10", "four": "11", "ot": "", "points": "0", "outcome": "39" } } }, ... etc ... etc ... ]
Please help!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘POST events via API error’ is closed to new replies.