OAUTH2 POST getting 404 error

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
gbuxton
Posts: 2
Joined: Tue Feb 04, 2025 2:00 pm

OAUTH2 POST getting 404 error

Post by gbuxton »

Keep getting 404 error code on the POST below. Able to use POSTMAN to get access token then in turn use that token to get an invoice image from SAP. Can't get it to work in /free. client, secret etc masked. Any help appreciated.


H DFTACTGRP(*NO) ACTGRP(*NEW)
H BNDDIR('HTTPAPI':'YAJL')

*
* CONCUR: Get Invoice Image from Request Id
*

D INVIMAGE PR ExtPgm('INVIMAGE')
D filein 20A const
D INVIMAGE PI
D filein 20A const

D/copy qrpglesrc,httpapi_h
D/copy qrpglesrc,ifsio_h
D/copy qrpglesrc,yajl_h

D ifsnm s 150a varying
D rc s 10I 0
D msg s 52A
D url s 1000a varying


/free
dcl-s client varchar(4096);
dcl-s secret varchar(4096);
dcl-s sendData varchar(16384);
dcl-s ResultStr varchar(16000000);
dcl-ds authResult qualified;
access_token varchar(4096);
token_type varchar(20);
expires_in int(10);
end-ds;
client = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

c callp http_debug(*ON)


sendData = 'grant_type=refresh_token'
+ '&client_id=' + http_urlEncode(client)
+ '&client_secret=' + http_urlEncode(secret)
+ '&refresh_token=xxxxxxxxxxxxxxxxxxxxxxxxxxx';

rc = http_req( 'POST'
:'https://us2.api.concursolutions.com/oauth/v0/token'
: *omit
: resultStr // String to receive the results
: *omit
: sendData
: 'application/x-www-form-urlencoded');

if rc <> 1; GETTING RETURN CODE 404 NO MATTER WHAT I TRY
msg = http_error;
dsply msg;
else;
data-into authResult %DATA(resultStr)
%PARSER('YAJLINTO');

url='https://us2.api.concursolutions.com/api ... 0/invoice/'
+'XXXXXXXXXXXXXXXXXXXX';

**Retrieve Invoice Image with Get
ifsnm = '/home/CONCUR/Inbound_Image/'+ filein;

// now you have authResult structure that contains the
// access token.
// When you need to call an API using that token, you do this:

HTTP_setAuth( HTTP_AUTH_BEARER: '': authResult.access_token);


c eval rc = http_url_get( url: ifsnm )

if rc <> 1;
msg = http_error;
dsply msg;
endif;
endif;

*inlr = *on;
/end-free
jonboy49
Posts: 239
Joined: Wed Jul 28, 2021 8:18 pm

Re: OAUTH2 POST getting 404 error

Post by jonboy49 »

Are you sure that the URLs that you posted are correct? When I try those URLs in postman I get a 404 every time.
gbuxton
Posts: 2
Joined: Tue Feb 04, 2025 2:00 pm

Re: OAUTH2 POST getting 404 error

Post by gbuxton »

Thanks, I was missing a 2 at the end of oauth in the first URL. Should have been oauth2. I must have looked at that 50 times and didn't notice. Thanks again.
jonboy49
Posts: 239
Joined: Wed Jul 28, 2021 8:18 pm

Re: OAUTH2 POST getting 404 error

Post by jonboy49 »

Good. I was going to ask if you were using the original oauth as all the URLs I have seen so far for oauth2 had a "2" in the URL.
Post Reply