Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Web API    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
UPS Token API
Clinton Lupo 
    
14 months ago
Been working on adding APIs to a database I created for my work's Service Department. Had no troubles with one for sales tax rate and FedEx tracking. However, UPS's API for just getting a token has been stumping me. At this point I keep getting Error: 400 -
Response: {"response":{"errors":[{"code":"10400","message":"Invalid/Missing Authorization Header"}]}} with the following VBA. Anyone have experience with UPS and their APIs?

DetailsPublic Sub TokenBtn_Click()
    Dim XMLHTTP As Object
    Dim ResponseText As String
    Dim MyURL As String ' Corrected variable name
    Dim apiKey As String
    Dim apiSecretKey As String
    Dim requestBody As String
    Dim HttpStatusCode As Long
    Dim HttpStatusText As String
    Dim S As String
    
    apiKey = "XXXXXXXX"
    apiSecretKey = "XXXXXXXXX"
    MyURL = "https://wwwcie.ups.com/security/v1/oauth/token"

    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
    XMLHTTP.Open "POST", MyURL, False
    XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    XMLHTTP.setRequestHeader "x-merchant-id", apiKey
    XMLHTTP.setRequestHeader "Authorization", "Basic " & Base64Encode(apiKey & ":" & apiSecretKey)
    
    requestBody = "{""grant_type"":""client_credentials""}"
    'requestBody = "grant_type=client_credentials"
    
    'do stuff w/requestBody
    XMLHTTP.SEnd requestBody
    
    HttpStatusCode = XMLHTTP.Status
    HttpStatusText = XMLHTTP.StatusText
    ResponseText = XMLHTTP.ResponseText
    
    S = ResponseText

    Set XMLHTTP = Nothing

    If HttpStatusCode = 200 Then
        Me.TokenTxt.Value = S

        Else
        Me.TokenTxt.Value = "Error: " & HttpStatusCode & " - " & HttpStatusText & vbCrLf & "Response: " & ResponseText

    End If
    
End Sub
Clinton Lupo OP  @Reply  
    
14 months ago
Solved, I went way to complicated. Found the following VBA code that works for getting a token from UPS' API.
Dim strHead As String, strClientId As String, strClientSecret As String
strClientId = "xxx"
strClientSecret = "xxx"
strHead = strClientId & ":" & strClientSecret

    With CreateObject("MSXML2.ServerXMLHTTP")
        .Open "POST", "https://wwwcie.ups.com/security/v1/oauth/token"
        .setRequestHeader "Authorization", "Basic " + EncodeBase64(strHead)
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .setRequestHeader "x-merchant-id", "string"
        .send "grant_type=client_credentials"
        Me.TokenTxt.Value = .ResponseText

    End With

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Web API.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/16/2026 4:06:58 AM. PLT: 0s