{"id":189,"date":"2010-04-25T02:38:53","date_gmt":"2010-04-25T02:38:53","guid":{"rendered":"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/?p=189"},"modified":"2015-05-22T00:09:27","modified_gmt":"2015-05-22T00:09:27","slug":"awarding-commission-via-http-get-or-post","status":"publish","type":"post","link":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189","title":{"rendered":"API &#8211; Awarding Commission via HTTP GET or POST"},"content":{"rendered":"<p><strong><span style=\"color: #ff0000;\">This documentation is only for developers. If you are not a developer with good PHP coding skills then you have no need to read this.<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\"><strong>It is very hard to troubleshoot another coder\u2019s code. So if you use this documentation and do a custom integration yourself then please note that we cannot offer you any support in terms of what is wrong with your code. You will need to hire us to take a look at your code and correct any mistakes you made.<\/strong><\/span><\/p>\n<p>Depending on your situation you may need to be able to award commission via a HTTP GET or POST request. WP Affiliate Platform has an API for awarding commission using a standard HTTP GET or POST request. If you want to use this API then you need to enable it from the settings menu. The following is a screenshot of this section in the settings menu:<\/p>\n<div id=\"attachment_607\" style=\"width: 510px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-607\" class=\"size-full wp-image-607\" title=\"wp-affiliate-api-remote-post-settings\" src=\"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png\" alt=\"\" width=\"500\" height=\"275\" srcset=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png 500w, https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings-300x165.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><p id=\"caption-attachment-607\" class=\"wp-caption-text\">Additional Integration Options Screenshot<\/p><\/div>\n<p>Once you enable it, you can start to send request to the specified URL to award commission remotely.<\/p>\n<p>You need a minimum of 3 pieces of information to award commission via a HTTP request. These are:<\/p>\n<ul>\n<li>Secret word (the secret word that you have specified in the settings)<\/li>\n<li>Referrer ID (the affiliate ID)<\/li>\n<li>Sale amount (commission will be calculated based on this amount)<\/li>\n<\/ul>\n<p>Optionally, you can pass in the following additional data too:<\/p>\n<ul>\n<li>Transaction ID (txn_id)<\/li>\n<li>Item ID (item_id)<\/li>\n<li>Buyer email address (buyer_email)<\/li>\n<\/ul>\n<h3>1. Awarding Commission via HTTP GET request<\/h3>\n<p>To award commission via HTTP GET use the following format:<\/p>\n<pre>http:\/\/www.example.com\/wp-content\/plugins\/wp-affiliate-platform\/api\/post.php?secret=XX&amp;ap_id=YY&amp;sale_amt=ZZ\r\n<\/pre>\n<p>Replace the &#8220;example.com&#8221;, &#8220;XX&#8221;, &#8220;YY&#8221;, &#8220;ZZ&#8221; with the appropriate value.<\/p>\n<h4>PHP Code Example<\/h4>\n<p>The following is an example of how to construct this link using PHP:<\/p>\n<pre>$secret = \"4bd39e2e4a7bb\";\r\n$referrer = \"amin21\";\r\n$sale_amt = \"29.95\";\r\n$prepared_data = \"?secret=\".$secret.\"&amp;ap_id=\".$referrer.\"&amp;sale_amt=\".$sale_amt;\r\n$get_url = \"http:\/\/www.example.com\/wp-content\/plugins\/wp-affiliate-platform\/api\/post.php\".$prepared_data;\r\n\/\/ Execute this GET Request\r\nfile_get_contents($get_url);\r\n<\/pre>\n<h3>2. Awarding Commission via HTTP POST request<\/h3>\n<p>To award commission via HTTP POST use the following format:<\/p>\n<pre>&lt;form method=\"post\" action=\"http:\/\/www.example.com\/wp-content\/plugins\/wp-affiliate-platform\/api\/post.php\"&gt;\r\n&lt;input type=\"hidden\" name=\"secret\" value=\"XX\"&gt;\r\n&lt;input type=\"hidden\" name=\"ap_id\" value=\"YY\"&gt;\r\n&lt;input type=\"hidden\" name=\"sale_amt\" value=\"ZZ\"&gt;\r\n&lt;input type=submit value=\"Submit Post\"&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<p>Replace the &#8220;example.com&#8221;, &#8220;XX&#8221;, &#8220;YY&#8221;, &#8220;ZZ&#8221; with the appropriate value.<\/p>\n<h4>PHP Code Example<\/h4>\n<p>If you are integrating the affiliate platform plugin with a Payment Gateway or a Shopping Cart in PHP then you can add the following example code to your post payment processing script or the &#8220;Thank You&#8221; page script to award commission after a payment:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2011\/03\/php-example-award-commission-http-post.txt\" target=\"_blank\">Example code to award commission using HTTP POST method<\/a><\/li>\n<\/ul>\n<h3>How to\u00a0Programmatically\u00a0Retrieve the Affiliate ID on a Page<\/h3>\n<p>If you are writing a script then you most likely want to code it up so the affiliate ID can be retrieved programmatically. The affiliate ID is stored in the cookie so just retrieve the value form the cookie. For example the following code will give you the affiliate ID if used in PHP:<\/p>\n<pre>$affiliate_id = $_COOKIE['ap_id'];\r\n<\/pre>\n<p>Now, you can use the &#8220;$affiliate_id&#8221; variable.<\/p>\n<h3>Calculating Commission in Your Script<\/h3>\n<p>Normally, if you send the total sale amount value to the API, it will calculate the commission based on your settings and award it to the affiliate. However, you can choose to calculate the total commission in your script then send that amount to the API. The commission amount you send to the API will be given directly to the affiliate (no additional calculation will be performed).<\/p>\n<p>You can pass the total commission amount value using the &#8220;commission_amt&#8221; parameter in your API request. Below is an example:<\/p>\n<pre>&lt;form method=\"post\" action=\"http:\/\/www.example.com\/wp-content\/plugins\/wp-affiliate-platform\/api\/post.php\"&gt;\r\n&lt;input type=\"hidden\" name=\"secret\" value=\"XX\"&gt;\r\n&lt;input type=\"hidden\" name=\"ap_id\" value=\"YY\"&gt;\r\n&lt;input type=\"hidden\" name=\"sale_amt\" value=\"ZZ\"&gt;\r\n&lt;input type=\"hidden\" name=\"commission_amt\" value=\"AA\"&gt;\r\n&lt;input type=submit value=\"Submit Post\"&gt; \r\n&lt;\/form&gt;\r\n<\/pre>\n<p>Replace the &#8220;example.com&#8221;, &#8220;XX&#8221;, &#8220;YY&#8221;, &#8220;ZZ&#8221;, &#8220;AA&#8221; with the appropriate value.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This documentation is only for developers. If you are not a developer with good PHP coding skills then you have no need to read this. It is very hard to troubleshoot another coder\u2019s code. So if you use this documentation and do a custom integration yourself then please note that we cannot offer you any [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[12],"tags":[11,13,5],"class_list":{"0":"post-189","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-3rd-party-cart-integration","7":"tag-3rd-party-integration","8":"tag-shopping-cart-integration","9":"tag-wp-affiliate-platform","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Awarding Commission via HTTP GET or POST - WordPress Affiliate Platform<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#\/schema\/person\/b3a690506213824832751de546a340fb\"},\"headline\":\"API &#8211; Awarding Commission via HTTP GET or POST\",\"datePublished\":\"2010-04-25T02:38:53+00:00\",\"dateModified\":\"2015-05-22T00:09:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189\"},\"wordCount\":559,\"commentCount\":14,\"image\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png\",\"keywords\":[\"3rd party Integration\",\"Shopping Cart Integration\",\"WP Affiliate Platform\"],\"articleSection\":[\"3rd Party Cart Integration\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189\",\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189\",\"name\":\"Awarding Commission via HTTP GET or POST - WordPress Affiliate Platform\",\"isPartOf\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png\",\"datePublished\":\"2010-04-25T02:38:53+00:00\",\"dateModified\":\"2015-05-22T00:09:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#\/schema\/person\/b3a690506213824832751de546a340fb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage\",\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png\",\"contentUrl\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png\",\"width\":\"500\",\"height\":\"275\",\"caption\":\"Additional Integration Options Screenshot\"},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#website\",\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/\",\"name\":\"WordPress Affiliate Platform\",\"description\":\"Take control of your affiliates and drive more sales\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#\/schema\/person\/b3a690506213824832751de546a340fb\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Awarding Commission via HTTP GET or POST - WordPress Affiliate Platform","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189","twitter_misc":{"Written by":"admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#article","isPartOf":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189"},"author":{"name":"admin","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#\/schema\/person\/b3a690506213824832751de546a340fb"},"headline":"API &#8211; Awarding Commission via HTTP GET or POST","datePublished":"2010-04-25T02:38:53+00:00","dateModified":"2015-05-22T00:09:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189"},"wordCount":559,"commentCount":14,"image":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage"},"thumbnailUrl":"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png","keywords":["3rd party Integration","Shopping Cart Integration","WP Affiliate Platform"],"articleSection":["3rd Party Cart Integration"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189","url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189","name":"Awarding Commission via HTTP GET or POST - WordPress Affiliate Platform","isPartOf":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage"},"image":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage"},"thumbnailUrl":"http:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png","datePublished":"2010-04-25T02:38:53+00:00","dateModified":"2015-05-22T00:09:27+00:00","author":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#\/schema\/person\/b3a690506213824832751de546a340fb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/awarding-commission-via-http-get-or-post-189#primaryimage","url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png","contentUrl":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-content\/uploads\/2010\/04\/wp-affiliate-api-remote-post-settings.png","width":"500","height":"275","caption":"Additional Integration Options Screenshot"},{"@type":"WebSite","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#website","url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/","name":"WordPress Affiliate Platform","description":"Take control of your affiliates and drive more sales","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/#\/schema\/person\/b3a690506213824832751de546a340fb","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":0,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-affiliate\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}