Track a show’s references from code, read their click counts, or set their affiliate URL, country rules and expiry
These are the routes behind the episode editor’s → Track button and a tracked link’s settings. Every method needs manage_options (send an X-WP-Nonce for wp_rest from a browser) and Outlinks switched on for {show_id}, else 403 benecaster_outlinks_not_active.
GET /benecaster-outlinks/v1/shows/{show_id}/redirectsanswers{ go_base, items }. Each item hasid,slug,reference_id,destination_url,affiliate_url,expiry_date,expiry_fallback_url,geo_rules(each{ country_code, destination_url, affiliate_url }),clicksandgo_url.clickscounts people only.reference_idis null for a standalone link; unset settings are null.POSTwith{ reference_id, slug }answers201with one item. The destination is always the Reference Library item’s own URL, read for the show in the path; any URL you send is ignored.slugis cleaned withsanitize_title()(at most 100 characters) and must be unique across the whole site.PATCH …/redirects/{redirect_id}with any ofaffiliate_url,expiry_date,expiry_fallback_urlandgeo_rulesanswers200with the item. Only the keys you send change;''ornullclears one.expiry_dateisYYYY-MM-DDon the site’s calendar, and the link expires the day after it. The link must belong to{show_id}, else404 benecaster_outlinks_redirect_not_found.
Code
<?php
$request = new WP_REST_Request( 'POST', '/benecaster-outlinks/v1/shows/12/redirects' );
$request->set_body_params( [ 'reference_id' => 41, 'slug' => 'lean-startup' ] );
$response = rest_do_request( $request ); // As a user with manage_options.
if ( $response->is_error() && 'benecaster_outlinks_slug_taken' === $response->as_error()->get_error_code() ) {
$suggestion = $response->as_error()->get_error_data()['suggestion']; // e.g. 'lean-startup-2'
}
Need this built rather than just documented? See our services →