Skip to main content

Track a show’s references from code, read their click counts, or set their affiliate URL, country rules and expiry

Premium Advanced

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}/redirects answers { go_base, items }. Each item has id, slug, reference_id, destination_url, affiliate_url, expiry_date, expiry_fallback_url, geo_rules (each { country_code, destination_url, affiliate_url }), clicks and go_url. clicks counts people only. reference_id is null for a standalone link; unset settings are null.
  • POST with { reference_id, slug } answers 201 with 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. slug is cleaned with sanitize_title() (at most 100 characters) and must be unique across the whole site.
  • PATCH …/redirects/{redirect_id} with any of affiliate_url, expiry_date, expiry_fallback_url and geo_rules answers 200 with the item. Only the keys you send change; '' or null clears one. expiry_date is YYYY-MM-DD on the site’s calendar, and the link expires the day after it. The link must belong to {show_id}, else 404 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'
}

View on GitHub →

Need this built rather than just documented? See our services →