PayPal API – Sending partner-referrals keeps coming back as Unauthorised: A Step-by-Step Guide to Resolve the Issue
Image by Kase - hkhazo.biz.id

PayPal API – Sending partner-referrals keeps coming back as Unauthorised: A Step-by-Step Guide to Resolve the Issue

Posted on

Are you struggling with the PayPal API and receiving an “Unauthorised” error when sending partner-referrals? You’re not alone! Many developers have faced this issue, and it’s often due to a simple mistake or misconfiguration. In this article, we’ll take you by the hand and walk you through the troubleshooting process to resolve this frustrating problem once and for all.

Understanding the Partner-Referrals API

The PayPal Partner-Referrals API is a powerful tool that allows you to reward your partners for referring new customers to your business. However, to use this API, you need to have the necessary permissions and configurations in place. In this section, we’ll cover the basics of the Partner-Referrals API and what you need to get started.

Requirements for Using the Partner-Referrals API

  • A PayPal Business account with the Partner-Referrals feature enabled
  • A PayPal API username and password
  • A valid API signature or certificate
  • The PayPal API SDK for your programming language of choice

Make sure you have these requirements in place before proceeding. If you’re unsure about any of these steps, refer to the PayPal API documentation for more information.

Common Causes of the “Unauthorised” Error

So, why are you getting the “Unauthorised” error when sending partner-referrals? Here are some common causes:

  1. Invalid API credentials: Double-check your API username, password, and signature or certificate. Make sure they’re correct and up-to-date.
  2. Insufficient permissions: Ensure your API user has the necessary permissions to access the Partner-Referrals API.
  3. Incorrect API endpoint: Verify that you’re using the correct API endpoint for sending partner-referrals.
  4. Invalid request format: Check that your request is formatted correctly and meets the API’s requirements.

Let’s dive deeper into each of these causes and provide solutions to resolve the “Unauthorised” error.

Solution 1: Verify API Credentials

First things first, let’s check your API credentials. Make sure you have the correct API username, password, and signature or certificate.

api_username = "your_api_username"
api_password = "your_api_password"
api_signature = "your_api_signature"

If you’re using a certificate, ensure it’s properly configured and uploaded to the PayPal API.

Solution 2: Check API Permissions

Next, ensure your API user has the necessary permissions to access the Partner-Referrals API. Log in to your PayPal account and navigate to the API Permissions section.

Permission Description
PartnerReferral.Send Allows sending partner-referrals

Make sure the “PartnerReferral.Send” permission is enabled for your API user. If not, grant the necessary permission and try sending the partner-referral again.

Solution 3: Verify API Endpoint

The Partner-Referrals API uses a specific endpoint for sending partner-referrals. Ensure you’re using the correct endpoint:

https://api.paypal.com/v1/incentives/partner-referrals

Double-check that you’re using the correct endpoint and HTTP method (POST) in your API request.

Solution 4: Correct Request Format

Finally, ensure your request is formatted correctly and meets the API’s requirements. Here’s an example of a valid request:

{
  "reference_id": "UNIQUE_REFERENCE_ID",
  "partner_id": "PARTNER_ID",
  "amount": {
    "currency_code": "USD",
    "value": "10.00"
  },
  "description": "Partner-referral incentive"
}

Make sure to replace the placeholders with your actual values and ensure the request is properly JSON-encoded.

Putting it all Together

Now that we’ve covered the common causes and solutions, let’s put it all together. Here’s an example code snippet in Python using the PayPal API SDK:

import paypalrestsdk

# Set API credentials and endpoint
api_username = "your_api_username"
api_password = "your_api_password"
api_signature = "your_api_signature"
api_endpoint = "https://api.paypal.com/v1/incentives/partner-referrals"

# Create a PayPal API client
client = paypalrestsdk.ApiClient({
  "mode": "sandbox",  # or "live"
  "client_id": api_username,
  "client_secret": api_password
})

# Set partner-referral details
partner_referral = {
  "reference_id": "UNIQUE_REFERENCE_ID",
  "partner_id": "PARTNER_ID",
  "amount": {
    "currency_code": "USD",
    "value": "10.00"
  },
  "description": "Partner-referral incentive"
}

# Send partner-referral request
response = client.post(api_endpoint, partner_referral)

# Check response status
if response.status_code == 201:
  print("Partner-referral sent successfully!")
else:
  print("Error sending partner-referral:", response.text)

Replace the placeholders with your actual values and ensure you have the correct API credentials and permissions in place.

Conclusion

In conclusion, the “Unauthorised” error when sending partner-referrals via the PayPal API can be frustrating, but it’s often due to a simple mistake or misconfiguration. By following the steps outlined in this article, you should be able to resolve the issue and successfully send partner-referrals. Remember to double-check your API credentials, permissions, endpoint, and request format to ensure everything is correct.

If you’re still experiencing issues, refer to the PayPal API documentation and support resources for further assistance.

Happy coding!

Frequently Asked Question

Getting stuck with PayPal API partner-referrals? Don’t worry, we’ve got you covered!

Why am I getting an “Unauthorised” error when sending partner-referrals through the PayPal API?

This error usually occurs when the API credentials or access token used to send the partner-referral request are invalid or have insufficient permissions. Make sure to double-check your API credentials and access token to ensure they are correct and have the necessary permissions.

How do I obtain the necessary permissions to send partner-referrals through the PayPal API?

To obtain the necessary permissions, you need to register for a PayPal Partner Program account and apply for the Partner Referrals API. Once approved, you’ll receive the necessary API credentials and access token to send partner-referrals. Additionally, ensure that the API credentials and access token are properly configured and authenticated in your API requests.

What is the correct API endpoint and request format to send partner-referrals through the PayPal API?

The correct API endpoint to send partner-referrals is `/partner-referrals`. The request format should be in JSON, and it should include the required parameters such as `partner-referral-token`, `partner-referral-id`, and `tracking-id`. Make sure to refer to the PayPal API documentation for the exact request format and required parameters.

How do I troubleshoot issues with sending partner-referrals through the PayPal API?

To troubleshoot issues, start by checking the API response error messages and codes. Use tools like Postman or cURL to test your API requests and verify the response. You can also check the PayPal API documentation and developer community forums for common issues and solutions. If the issue persists, contact PayPal’s API support team for further assistance.

What are some common mistakes to avoid when implementing the PayPal API for partner-referrals?

Common mistakes to avoid include using invalid or expired API credentials, incorrect API endpoint URLs, and insufficient permissions. Additionally, make sure to handle errors and exceptions properly, and test your API implementation thoroughly before going live. It’s also essential to comply with PayPal’s API terms and conditions, as well as their branding and marketing guidelines.

Leave a Reply

Your email address will not be published. Required fields are marked *