API Reference

Step One: Integrate Click Tracking

Add the one-line script below to your main site template just before the closing </body> tag. This script must be on every page, as it takes the tracking URL and turns it into a first-party cookie.

<script defer src="https://static.shopmy.us/Affiliates/sms_aff_clicktrack.js"></script>


Step Two: Integrate Order Tracking

  1. Locate the thankyou.php file

  2. Add the script in the block below to the end of this HTML file

    1. 
      <script>
        const cookies = document.cookie.split(';').reduce((res, cookie) => ({ ...res, [cookie.split('=')[0].trim()]: cookie.split('=')[1].trim() }), {});
        const { sms_click_id } = cookies;
        const code = "<?php echo wp_kses_post( $order->get_coupon_codes()[0] ); ?>";
        fetch('https://api.shopmy.us/api/order_confirmation', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            orderAmount: <?php echo wp_kses_post( $order->get_total() ); ?>,
            orderId: <?php echo esc_html( $order->get_order_number() ); ?>,
            clickId: sms_click_id,
            currency: "<?php echo esc_html( $order->get_currency() ); ?>",
            is_returning_customer: false,
            code,
            page_url: window.location.href
          })
        }).then(r => {
          if (!r.ok) throw new Error('Invalid order request sent');
          r.json();
        }).then(result => {
            const now = new Date();
            document.cookie = `sms_click_id=;expires=${now.toUTCString()};path=/;`;
            document.cookie = `sms_click_time=;expires=${now.toUTCString()};path=/;`;
        }).catch(() => {
          // ignore the error
        });
      </script>
      


Step Three: Handle Order Cancellations

Configure a POST request to be sent to the following endpoint whenever an order is cancelled. This is crucial for maintaining accurate tracking and reporting in our system.

📘

This endpoint uses your unique Brand Developer Key for authorization. Always keep your key confidential to ensure security.

fetch(`https://api.shopmy.us/api/Affiliates/cancel`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer <YOUR_DEVELOPER_KEY>`,
  },
  body: JSON.stringify({
    order_id: '123456',
  })
})


Step Four: Handle Order Updates

Configure a POST request to be sent to the following endpoint whenever an order is updated. We define an order update as whenever a order has new total amount, or currency change. This is crucial for maintaining accurate tracking and reporting in our system.

📘

This endpoint uses your unique Brand Developer Key for authorization. Always keep your key confidential to ensure security

fetch(`https://api.shopmy.us/api/Affiliates/update`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer <YOUR_DEVELOPER_KEY>`,
  },
  body: JSON.stringify({
    order_id: '123456',
    currency: 'USD',
    new_order_amount: '1234.56'
  })
})

Step Five: Request Testing

Contact your Brand Success Manager to place a test order and test the integration end-to-end. We will communicate with you any test order IDs we place so they can be cancelled after the integration is verified.


📘

By adding our integration code to your site, you are agreeing to the terms of the ShopMy affiliate network. Please review these terms here.