Re: Auth 2.0
Brad Stone <[email protected]>
| Newsgroups | gmane.comp.lang.as400.rpg |
|---|---|
| Message-ID | <CAAGV8OfNf1c9hMRo8nCp-rYmVJixzhnN=XE7r6FqJfK1+npgkg@mail.gmail.com> |
Post the request, not the code if you can. You'll probably see the issue. HTTPAPI must have a "debug" mode, right? On Tue, Oct 14, 2025 at 11:10 AM Jean-Marc DUVAL via RPG400-L < [email protected]> wrote: > Hi, > > Why > rc = http_req('POST' > : APITokenURL > : ResponseFile > : *omit > : *omit > : FormData > : 'application/x-www-form-urlencoded'); > and not > rc = http_req('POST' > : APITokenURL > : ResponseFile > : *omit > : *omit > : FormData > : Headers); > > -----Message d'origine----- > De : RPG400-L <[email protected]> De la part de > (WalzCraft) Jerry Forss > Envoyé : mardi 14 octobre 2025 17:54 > À : RPG programming on IBM i <[email protected]> > Objet : Auth 2.0 > > > > ATTENTION : Ce message provient d'une source EXTERNE. Veuillez n'ouvrir > les liens ou pièces jointes que si vous êtes sûr de l'expéditeur. > > > > 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://urldefense.com/v3/__http://www.w3.org/TR/html4/strict.dtd__;!!J76aczzK!xAjRZysEN8m9RA6wZidwhN2QTclHubpQuBYJVnQc3wqkUxK9ZGhxbLN8iWEQRg0dQzKxgDXGtlOFJ69DFXxs4zi0$ > "> <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://urldefense.com/v3/__http://www.walzcraft.com__;!!J76aczzK!xAjRZysEN8m9RA6wZidwhN2QTclHubpQuBYJVnQc3wqkUxK9ZGhxbLN8iWEQRg0dQzKxgDXGtlOFJ69DFfq5xCnQ$ > < > https://urldefense.com/v3/__http://www.walzcraft.com__;!!J76aczzK!xAjRZysEN8m9RA6wZidwhN2QTclHubpQuBYJVnQc3wqkUxK9ZGhxbLN8iWEQRg0dQzKxgDXGtlOFJ69DFfq5xCnQ$ > > 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://urldefense.com/v3/__https://lists.midrange.com/mailman/listinfo/rpg400-l__;!!J76aczzK!xAjRZysEN8m9RA6wZidwhN2QTclHubpQuBYJVnQc3wqkUxK9ZGhxbLN8iWEQRg0dQzKxgDXGtlOFJ69DFXgC-sSS$ > or email: [email protected] > Before posting, please take a moment to review the archives at > https://urldefense.com/v3/__https://archive.midrange.com/rpg400-l__;!!J76aczzK!xAjRZysEN8m9RA6wZidwhN2QTclHubpQuBYJVnQc3wqkUxK9ZGhxbLN8iWEQRg0dQzKxgDXGtlOFJ69DFd1JxbRO$ > . > > Please contact [email protected] for any subscription related > questions. > > -- > 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: [email protected] > Before posting, please take a moment to review the archives > at https://archive.midrange.com/rpg400-l. > > Please contact [email protected] for any subscription related > questions. > > -- 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: [email protected] Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l. Please contact [email protected] for any subscription related questions.