Gift card function

I tried following this guide to create gift card. But its not working. I know my webhook is set up correctly as its runs other functions without problems. Is there anything I am missing?

I even tried with my own code, but no luck. Is there anything I am doing wrong?

<?php
$json = file_get_contents('php://input');
$body = json_decode($json, true);

if (is_null($body) or !isset($body['eventName'])) {
	header('HTTP/1.1 400 Bad Request');
	return;
}
switch ($body['eventName']) {
	case 'order.completed':

		addGiftCardToDiscounts();
		break;
}
header('HTTP/1.1 200 OK');




function addGiftCardToDiscounts(){
		
	$ch = curl_init();
	
	curl_setopt($ch, CURLOPT_URL, 'https://app.snipcart.com/api/discounts');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "{ name: 'Free shipping',\n        trigger: 'Total',\n        totalToReach: 150,\n        type: 'Shipping',\n        shippingDescription: 'Free shipping',\n        shippingCost: 0,\n        shippingGuaranteedDaysToDelivery: 10 }");
	curl_setopt($ch, CURLOPT_USERPWD, 'API KEY');
	
	$headers = array();
	$headers[] = 'Content-Type: application/json';
	$headers[] = 'Accept: application/json';
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	
	$result = curl_exec($ch);
	if (curl_errno($ch)) {
		echo 'Error:' . curl_error($ch);
	}
	curl_close($ch);
	
	}
	

There was a post recently on our support forum and another Snipcart user explained how he did it: