401 Unauthorised when calling Cybersource https://batch.cybersource.com/upload/UploadBatchFile endpoint

65 Views Asked by At

When making a call to Cybersource's https://batch.cybersource.com/upload/UploadBatchFile endpoint we receive 401 Unauthorised.

The documentation (named "Offline Transaction File Submission| Batch File Reports") for this endpoint was supplied to us a by large US bank but is actually not currently available from Cybersource developer portal directly.

We've been assured this endpoint should work as existing bank customers have successfully integrated already but as Cybersource no longer have this documentation on their website we have our suspicions as to whether this endpoint is actually still valid / supported.

Using a simple C# console app we're calling https://batchtest.cybersource.com/upload/UploadBatchFile for batch file uploading. When run we receive a 401 Unauthorised response. We are expecting a 2xx response. The code is below:

using System.Net.Http.Headers;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
public class Program
{
    static void Main(string[] args)
    {

        // set paths to external resources
        var batchCsvFilePath = Path.Combine(Environment.CurrentDirectory, "SupportingFiles", "batch.csv");
        var clientCertificatePath = Path.Combine(Environment.CurrentDirectory, "SupportingFiles", "clientcert.p12");

        // encode the credentials
        var encodedAuthString = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password"));

        // set up cert
        var cert = new X509Certificate2(clientCertificatePath, "password");

        // setup multi-part form data content
        var content = new MultipartFormDataContent
        {
            new StreamContent(File.OpenRead(batchCsvFilePath))
        };
        content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

        // setup HTTP POST request message
        var requestMessage = new HttpRequestMessage(HttpMethod.Post, "https://batchtest.cybersource.com/upload/UploadBatchFile");
        requestMessage.Headers.Add("Authorization", encodedAuthString);
        requestMessage.Content = content;

        // setup HTTP client handler
        var httpHandler = new HttpClientHandler();
        httpHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
        httpHandler.SslProtocols = SslProtocols.Tls12;
        httpHandler.ClientCertificates.Add(cert);

        // setup HTTP client and post message
        var httpClient = new HttpClient(httpHandler);
        var responseMessage = httpClient.Send(requestMessage);

We've validated the credentials are correct by logging in to the Cybersource Business center.

We've also validated the cert and secret key are valid too by testing the APi call with the cert as well as with an invalid secret key value. In both cases we receive a TLS error.

Anyone else managed to integrate Batch File submissions programatically to Cybersource?

0

There are 0 best solutions below