1

I am trying to get the Paypal Access Token using what I believe to be the cURL equivalent in VBS. Here is the cURL post I am trying to https://developer.paypal.com/docs/api/get-an-access-token-curl/ and this is the VBScript code I am using

<%
    Dim Base64, ClientID, Secret 
    ClientID    = "ClientID" 
    Secret      = "Secret" 
    Base64      = "Base64" 
    Dim XMLHTTP : Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
    XMLHTTP.setOption 2, 13056 
    XMLHTTP.Open "POST", "https://api.sandbox.paypal.com/v1/oauth2/token", False, ClientID, Secret 
    XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    XMLHTTP.setRequestHeader "Accept", "application/json" 
    XMLHTTP.setRequestHeader "Accept-Language", "en_US" 
    XMLHTTP.setRequestHeader "Authorization", "Basic " & Base64 
    XMLHTTP.Send("grant_type=client_credentials") 

The error that the server returns is :

msxml6.dll error '80072f0c'

A certificate is required to complete client authentication

Paypal.asp, line 13 

I know there is a XMLHTTP.setOption 3, "LOCAL_MACHINE\My\api.sandbox.paypal.com" that can also be added to the code but from what I can see within the documentation I shouldn't need to install any certs on the server.

[ edit ]

This is the code Here that explains how this fix works. You can use your own cert it does not need to be a self signed cert, the important part is to use Step 2. Assign permissions to the certificate to give the web server permission to use that certificate.

<%
    Dim Base64, ClientID, Secret 
    ClientID    = "ClientID" 
    Secret      = "Secret" 
    Base64      = "Base64" 
    Dim XMLHTTP : Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
    XMLHTTP.setOption 2, 13056 
    XMLHTTP.setOption 3, "LOCAL_MACHINE\My\example.za.live" ' **Added** 
    XMLHTTP.Open "POST", "https://api.sandbox.paypal.com/v1/oauth2/token", False, ClientID, Secret 
    XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    XMLHTTP.setRequestHeader "Accept", "application/json" 
    XMLHTTP.setRequestHeader "Accept-Language", "en_US" 
    XMLHTTP.setRequestHeader "Authorization", "Basic " & Base64 
    XMLHTTP.Send("grant_type=client_credentials") 
  • Does this answer your question? [Can't use HTTPS with ServerXMLHTTP object](https://stackoverflow.com/a/47356036/2069605) (second answer) – Preston PHX Sep 22 '20 at 22:28
  • Thanks @PrestonPHX this worked perfectly for me, I just made an edit to the above so to that others can see how the fixed code works. – Hilton Siegert Sep 23 '20 at 08:47

0 Answers0