Search code examples
paypalpaypal-sandboxpaypal-rest-sdk

Is there any way to add tracking info on behalf of the clients?


Is there any way to add tracking info fields on behalf of other clients using the new REST API? If not, can I still create paypal apps that use the old API, or any other way?

There is an old Question that demonstrates what I am trying to do.

By following this Documentation page I managed to update info on my sandbox account using the following C# code...

private static string SendRequest()
{
    var client = new HttpClient();
    var end_point = "https://api.sandbox.paypal.com/v1/shipping/trackers-batch";
    try
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        var requestMessage = new HttpRequestMessage
        {
            RequestUri = new Uri(end_point),
            Method = HttpMethod.Post,

        };
        string clientId = "";
        string secret = "";

        requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic",
            Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes($"{clientId}:{secret}")));

        string body = File.ReadAllText("data.json");
        requestMessage.Content = new StringContent(body, Encoding.UTF8, "application/json");
        var x = client.SendAsync(requestMessage).Result;
        string responseStr = x.Content.ReadAsStringAsync().Result;

        return responseStr;
    }
    catch (Exception exp)
    {
        Debug.Print(exp.Message);
        return null;
    }
    finally
    {
        client.Dispose();
    }
}

data.json

{
  "trackers": [
    {
      "transaction_id": "04YE27.....",
      "tracking_number": "443844....",
      "status": "SHIPPED",
      "carrier": "FEDEX"
    }
  ]
}

But it fails to update another SandBox account data even when I granted the permissions from that account settings to my app. This is the server response:

{
   "tracker_identifiers":[

   ],
   "errors":[
      {
         "name":"NOT_AUTHORIZED",
         "message":"Authorization failed due to insufficient permissions",
         "details":[
            {
               "field":"/trackers/1/transaction_id",
               "value":"04YE27.....",
               "location":"body",
               "issue":"USER_NOT_AUTHORIZED",
               "description":"You are not authorized to add or modify tracking number for this transaction"
            }
         ],
         "links":[

         ]
      }
   ],
   "links":[
      {
         "href":"https://api.sandbox.paypal.com/v1/shipping/trackers-batch",
         "rel":"self",
         "method":"POST",
         "encType":"application/json"
      }
   ]
}

I can ask the users to give the required permissions to my app. but I can't ask everyone to create an app and give me their Client ID and secret.


Solution

  • I can't ask everyone to create an app and give me their Client ID and secret.

    This is exactly what you need to do to have this level of granular control over transaction-level information in their PayPal account.

    Besides creating an app for you and sharing its credentials, there isn't a mechanism for them to grant the permission.

    If not, can I still create paypal apps that use the old API, or any other way?

    The old APIs and apps do not offer a way to update tracking information. They also aren't supported for new integrations, and should no longer be used (backwards compatibility/maintenance only)