RE: [EXTERNAL] Auth 2.0

Greg Wilburn <gwilburn-kuYYJ3CQfvZxq3Q2jbZZw/[email protected]>
Newsgroups gmane.comp.lang.as400.rpg
Message-ID <PH0PR17MB4863D8825E17ACACFCC69D32DAE8A@PH0PR17MB4863.namprd17.prod.outlook.com>
I don't know the specs for that API, but most of the APIs I've dealt with us basic authentication for getting the token.

rc = http_setauth(HTTP_AUTH_BASIC :clientID  :clientSecret);

That puts them in the header, base64 encoded.


-----Original Message-----
From: RPG400-L <rpg400-l-bounces-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org> On Behalf Of (WalzCraft) Jerry Forss
Sent: Tuesday, October 14, 2025 11:54 AM
To: RPG programming on IBM i <[email protected]>
Subject: [EXTERNAL] Auth 2.0

Hi All

I am trying to build a new API to call TForce for shipping requests that uses Auth 2.0.

I have done this in the past for FedEx and works but having issues with TForce.

I can get the access token in Postman but is failing when I try from my RPG pgm.
I am sure it's just something basic I am not understanding.

Postman request

Authorization
               Auth Type           2.0

Body
               client_id               What we got for TForce
               client_secret       What we got for TForce
               scope                   What we got for TForce
               grant_type          client_credentials

Works fine getting token

My RPG code

// ====================================================================================
//  Prototype SetTokenHeader
// ====================================================================================

Dcl-Proc SetTokenHeader;

  // ----------------------------------------------------------------------------------
  //  Input Parameters
  // ----------------------------------------------------------------------------------

  Dcl-pi *N;
    Headers             VarChar(2000);
  End-pi;

  // ----------------------------------------------------------------------------------
  //  Local Parameters
  // ----------------------------------------------------------------------------------

  // ----------------------------------------------------------------------------------
  //  Data Structures
  // ----------------------------------------------------------------------------------

  // ----------------------------------------------------------------------------------
  // Mainline
  // ----------------------------------------------------------------------------------

  Headers = 'application/x-www-form-urlencoded' + CRLF;

End-Proc;

// ====================================================================================
//  Prototype CreateToken - Generate Token
// ====================================================================================

Dcl-Proc CreateToken;

  // ----------------------------------------------------------------------------------
  //  Input Parameters
  // ----------------------------------------------------------------------------------

//  Dcl-pi *n;
//    Token               VarChar(100);
//  End-pi;

  // ----------------------------------------------------------------------------------
  //  Local Parameters
  // ----------------------------------------------------------------------------------

  Dcl-S FormData             Varchar(1000);

  // ----------------------------------------------------------------------------------
  //  Data Structures
  // ----------------------------------------------------------------------------------

  // Token Response From API Call
  Dcl-ds TokenResponse       Qualified;

    access_token             VarChar(2000);
    token_type               Char(20);
    expires_in               Packed(7 : 0);
    scope                    Char(20);

  End-ds;

  // ----------------------------------------------------------------------------------
  // Mainline
  // ----------------------------------------------------------------------------------

  ResponseFile = %Trim(Path) + 'TForce_Token_Resp.json';
  Rc = http_xproc(HTTP_POINT_ADDL_HEADER : %paddr(SetTokenHeader));

  FormData = 'grant_type=client_credentials' +
             '&client_id=' + %Trim(ClientID) +
             '&client_secret=' + %Trim(APIKeyLive) +
             '&scope=' + %Trim(APIScope);

  rc = http_req('POST'
               : APITokenURL
               : ResponseFile
               : *omit
               : *omit
               : FormData
               : 'application/x-www-form-urlencoded');

Fails with RC of 400

Response json

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""https://protect.checkpoint.com/v2/r01/___http://www.w3.org/YWdmyrq9dxywnhy.iyi___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzoyYzkzYjEyMGNjZTM5ZGUyZDIxOWE3YTI0ZjgzNTBjODo3OjJhNmQ6MjgzOTQwNzAzMmE5MzhlODUwOGY0ZDJlNGFkMjM4MjY4ZDQ2MjQ5ODFkZTFmYTc5NDk3MzRjMmI0ZDliYjRhNTpwOlQ6VA">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</BODY></HTML>




Subject to Change Notice:

WalzCraft reserves the right to improve designs, and to change specifications without notice.

Confidentiality Notice:

This message and any attachments may contain confidential and privileged information that is protected by law. The information contained herein is transmitted for the sole use of the intended recipient(s) and should "only" pertain to "WalzCraft" company matters. If you are not the intended recipient or designated agent of the recipient of such information, you are hereby notified that any use, dissemination, copying or retention of this email or the information contained herein is strictly prohibited and may subject you to penalties under federal and/or state law. If you received this email in error, please notify the sender immediately and permanently delete this email. Thank You

WalzCraft PO Box 1748 La Crosse, WI, 54602-1748
https://protect.checkpoint.com/v2/r01/___www.walzcraft.com___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzoyYzkzYjEyMGNjZTM5ZGUyZDIxOWE3YTI0ZjgzNTBjODo3OmJmNGE6MDI0NGZhMTA2ZmJhMWRhYmYzZTNmYTc0NTQzYjUwZTI3Y2ZkZTI2MWRjZjU3YWQ4NzRkNmM2YjA5MWUxYzU1MDpwOlQ6Rg<https://protect.checkpoint.com/v2/r01/___http://www.walzcraft.com___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzoyYzkzYjEyMGNjZTM5ZGUyZDIxOWE3YTI0ZjgzNTBjODo3OmFjZjE6NGE0NDBiMzQyN2NjZTViMTk2ODg5OWE5NTg0ZWVlNDk2NjQ5OWFjMzA3OTQwMGU3MTRmYjIxZjQ0ZTBjZWQzZDpwOlQ6VA> Phone: 1-800-237-1326
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://protect.checkpoint.com/v2/r01/___https://lists.midrange.com/rfnqrfsdqnxynsktdwul955-q___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzoyYzkzYjEyMGNjZTM5ZGUyZDIxOWE3YTI0ZjgzNTBjODo3OmExMDk6YWUyYjcwZGE3ODhlY2E0MTAxNmFjMWE5OTgxMzJkYzgxZjQ5Y2JhNmYyMWZjYzRhMGM2OTRlZDE2M2IyMTQ2MjpwOlQ6VA
or email: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
Before posting, please take a moment to review the archives
at https://protect.checkpoint.com/v2/r01/___https://archive.midrange.com/wul955-q___.YzJ1OnRvdGFsYml6ZnVsZmlsbG1lbnQxOmM6bzoyYzkzYjEyMGNjZTM5ZGUyZDIxOWE3YTI0ZjgzNTBjODo3OjUwODc6NGIyOTZhYTY2ODljYzhlMWJkMjE1YzAxMWI3ZmZhYzczNTRiYzE0MWEzNTQxYTRjOGU0ODZmZTQxOGJkYjBhNTpwOlQ6VA.

Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions.

[CAUTION! This email originated outside of the organization. Please do not open attachments or click links from an unknown or suspicious origin.]

Greg Wilburn
Director of IT
301.895.3792 ext. 1231
-- 
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.