Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cartpauj/976017a4ac3054a1b31d62836ca60095 to your computer and use it in GitHub Desktop.
Save cartpauj/976017a4ac3054a1b31d62836ca60095 to your computer and use it in GitHub Desktop.
Sample jQuery JSON REST API - MemberPress Developer Tools - Basic Authentication
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Access</title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
var settings = {
async: true,
crossDomain: true,
url: "http://site.com/wp-json/mp/v1/coupons",
method: "POST",
dataType: "json",
headers: {
'Authorization': 'Basic ' + btoa('user:password') //Using Application Passwords plugin for this
},
data: {
coupon_code: "TESTCODE2",
should_expire: 0,
discount_type: "dollar",
discount_amount: 25,
valid_memberships: [869],
trial: 1,
trial_days: 90,
trial_amount: 25
}
}
$.ajax(settings).done(function(response) {
console.log(response);
});
});
</script>
</head>
<body>
<p>Hi</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment