[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ftpapi] Getting a response from http_req with POST request



Hello Ed,

 

What do you do with myVar after the  http_req() is successful?

 

Thanks

 

 

Best Regards

 Jose Vasquez

(786) 259 - 2387

 

Vasquez Jimenez Software

Affordable Computer Solutions

Visit Us: WWW.VJSoftwares.com

 

 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx <ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx> On Behalf Of Ed Gisler
Sent: Monday, August 24, 2020 9:59 AM
To: FTPAPI/HTTPAPI mailing list <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>; Scott Klement <sk@xxxxxxxxxxxxxxxx>
Subject: Re: [Ftpapi] Getting a response from http_req with POST request

 

Thanks Scott, that worked.

On 08/22/2020 7:10 AM Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:

 

 

Hi Ed,

After the http_req() is successful, you can call http_header() to get the location header.

monitor;
  httpResponse = http_req('POST': uri: *OMIT: response: *OMIT: request: 'application/json');
on-error;
  httpcode = http_error();
endmon;


if httpResponse > 0;

   myVar = http_header('location');

endif;

 

On 8/21/2020 3:58 PM, Ed Gisler wrote:

This is my first program using http_req to call an API.  I successfully get the request written to the database, but I am not getting the "response" variable with a value.  "httpResponse" is coming back with "1".  "response" is empty.  I am including my code, log from running the program, and a copy of what happens when I run my json statement via a curl command.  In the "Response headers" of curl is a line for "location:".  I need to be able to retrieve the value after "/schools/".  This is my record id that I need if I want to delete the record or be able to just get that one record.  I can see this line in my log file also, so I know it is somehow getting returned, but I don't see it in the response field.

 

CODE:

**free
Ctl-Opt DFTNAME(EF0010) OPTION(*SRCSTMT) BNDDIR('HTTPAPI':'YAJL') DECEDIT('0.');

///////////////////////////////////////////////////////////////////////////////////////////////////
// Description:
// This program will do a POST transaction to the Schools resource.
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
// Files
///////////////////////////////////////////////////////////////////////////////////////////////////
Dcl-f DOAML90 Disk Usage(*Input) Keyed;
Dcl-f DOBML01 Disk Usage(*Input) Keyed;
Dcl-f EFAML01 Disk Usage(*Input) Keyed;

///////////////////////////////////////////////////////////////////////////////////////////////////
// Prototypes for Procedures
///////////////////////////////////////////////////////////////////////////////////////////////////
/COPY httpapi_h
/COPY yajl_h

///////////////////////////////////////////////////////////////////////////////////////////////////
// Program Parameters
///////////////////////////////////////////////////////////////////////////////////////////////////
// For call to EF0000 to get token
Dcl-pr EF0000 Extpgm('EF0000');
PgToken varchar(100);
End-pr;

Dcl-pi EF0010;
PgRecId char(9);
PgSyr char(4);
End-pi;

// For call to GetMachine to get machine name
Dcl-pr GetMachine Extpgm('GETMACHINE');
PgMachine char(10);
End-pr;

///////////////////////////////////////////////////////////////////////////////////////////////////
// Data Structures
///////////////////////////////////////////////////////////////////////////////////////////////////
DCL-DS Grades Qualified Dim(22) Inz;
Code Char(2);
Description Char(100);
END-DS;

///////////////////////////////////////////////////////////////////////////////////////////////////
// Fields
///////////////////////////////////////////////////////////////////////////////////////////////////

DCL-S uri char(2000);
DCL-S response varchar(16000000:4);
DCL-S request varchar(16000000:4);
DCL-S httpcode char(100);
DCL-S access_token varchar(100);
DCL-S numyr packed(4:0);
DCL-S grdIdx packed(2:0);
DCL-S savGrdIdx packed(2:0);
DCL-S preschool Ind;
DCL-S machine char(10);
DCL-S id char(100);
DCL-S httpResponse int(10:0);

///////////////////////////////////////////////////////////////////////////////////////////////////
// Main Process
///////////////////////////////////////////////////////////////////////////////////////////////////

// Get machine name
GetMachine(machine);

// Get EFA record
Chain machine EFAML01;

// Save URI for API call
uri = %TRIM(EfaUri) + '/data/v3/ed-fi/schools';

// Get token by calling EF0000
EF0000(access_token);

// Get DOA record
Chain PgRecId DOAML90;

// If found
If %Found(DOAML90);

// Initialize fields
preschool = *OFF;
grdIdx = 0;
savGrdIdx = 0;
numyr = %INT(PgSyr);

// Set limits to DOB
Setll (DoaDst:DoaSch:'000':numyr) DOBML01;

// Read DOB
Reade (DoaDst:DoaSch:'000':numyr) DOBML01;

// Do the following until done
// Increment array index by
// Move values to fields
// Read DOB
Dow Not %EOF(DOBML01);
Select;
When %Subst(DobGra:1:1) = 'P';
If not preschool;
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Preschool/Prekindergarten';
preschool = *ON;
Endif;
When DobGra = 'KG';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Kindergarten';
When DobGra = '01';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'First grade';
When DobGra = '02';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Second grade';
When DobGra = '03';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Third grade';
When DobGra = '04';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Fourth grade';
When DobGra = '05';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Fifth grade';
When DobGra = '06';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Sixth grade';
When DobGra = '07';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Seventh grade';
When DobGra = '08';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Eighth grade';
When DobGra = '09';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Ninth grade';
When DobGra = '10';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Tenth grade';
When DobGra = '11';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Eleven grade';
When DobGra = '12';
grdIdx += 1;
Grades(grdIdx).Code = DobGra;
Grades(grdIdx).Description = 'Twelfth grade';
Endsl;
Reade (DoaDst:DoaSch:'000':numyr) DOBML01;
Enddo;

// Save grade index
savGrdIdx = grdIdx;

// Build request

yajl_genOpen(*off);
yajl_beginObj();

id = ' ';
yajl_addChar('id': %trim(id));

yajl_beginArray('addresses');
yajl_beginObj();
yajl_addChar('addressTypeDescriptor':
%trim('uri://ed-fi.org/AddressTypeDescriptor#Physical'));
yajl_addChar('stateAbbreviationDescriptor':
%trim('uri://ed-fi.org/StateAbbreviationDescriptor#OR'));
yajl_addChar('city': %trim(DoaCty));
yajl_addChar('postalCode': %trim(%subst(DoaZip:1:5)));
yajl_addChar('streetNumberName': %trim(DoaSa1));
yajl_endObj();
yajl_endArray();

yajl_beginArray('educationOrganizationCategories');
yajl_beginObj();
yajl_addChar('educationOrganizationCategoryDescriptor':
%trim('uri://ed-fi.org/EducationOrganizationCategoryDescriptor#School'));
yajl_endObj();
yajl_endArray();

If savGrdIdx > 0;
grdIdx = 0;
yajl_beginArray('gradeLevels');
Dow grdIdx < savGrdIdx;
grdIdx += 1;
yajl_beginObj();
yajl_addChar('gradeLevelDescriptor':
'uri://ed-fi.org/GradeLevelDescriptor#' + %trim(Grades(grdIdx).Description));
yajl_endObj();
Enddo;
yajl_endArray();
Endif;

yajl_addNum('schoolId': %SUBST(DoaIid:5:4));
yajl_addChar('nameOfInstitution': %trim(DoaNam));
yajl_endObj();

request = yajl_copyBufStr();

yajl_genClose();

http_debug(*on: '/tmp/EF0010-log.txt');

//Set CCSID
http_SetCCSIDs(1208:0);

//Headers
http_xproc(HTTP_POINT_ADDL_HEADER
: %paddr(addl_headers) );

monitor;
httpResponse = http_req('POST': uri: *OMIT: response: *OMIT: request: 'application/json');
on-error;
httpcode = http_error();
endmon;

Endif;

// End of program
*INLR = *ON;

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// Procedure - Additional Headers
///////////////////////////////////////////////////////////////////////////////////////////////////
dcl-proc addl_headers;

dcl-pi addl_headers;
Headers varchar(32767);
end-pi;

dcl-c CRLF x'0d25';

// build header
Headers = 'accept:application/json' + CRLF +
'authorization:Bearer ' + access_token + CRLF;

end-proc;
///////////////////////////////////////////////////////////////////////////////////////////////////

 

 

LOG FILE:

HTTPAPI Ver 1.40 released 2019-08-15
NTLM Ver 1.4.0 released 2014-12-22
OS/400 Ver V7R3M0

New iconv() objects set, PostRem=1208. PostLoc=0. ProtRem=819. ProtLoc=0
http_persist_open(): entered
http_long_ParseURL(): entered
DNS resolver retrans: 2
DNS resolver retry : 99
DNS resolver options: x'00000136'
DNS default domain: LBLESD.K12.OR.US
DNS server found: 167.128.4.100
DNS server found: 167.128.4.101
https_init(): entered
QSSLPCL = *OPSYS
SSL version 2 support disabled
SSL version 3 support disabled
Old interface to TLS version 1.0 support enabled
TLS version 1.0 support enabled
TLS version 1.1 support enabled
TLS version 1.2 support enabled
-------------------------------------------------------------------------------------
Dump of local-side certificate information:
-------------------------------------------------------------------------------------
Nagle's algorithm (TCP_NODELAY) disabled.
SNI hostname set to: test.oregonnexus.org
-------------------------------------------------------------------------------------
Dump of server-side certificate information:
-------------------------------------------------------------------------------------
Cert Validation Code = 6000
-----BEGIN CERTIFICATE-----
MIIFXzCCBEegAwIBAgISBAEJ8m042qc0cLOpVhHzWStGMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0yMDA4MDcyMjU4MDFaFw0y
MDExMDUyMjU4MDFaMB8xHTAbBgNVBAMTFHRlc3Qub3JlZ29ubmV4dXMub3JnMIIB
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzhJHRDk+ijFMaD9SRO7oJmCR
69A5WNgWPn2jS8ZVSAkFaMy933fPUbhGkap3x1cLCbT8pjFoLO5mEEyDXGSRTG8Z
r/vw0oJu0pEBMOLEFQ28NGvFsQ8p0cFft07UFiwmYm8wsKJMi/bkDOAOkMw/jNdg
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FQVKmyyEt+aw9YTswACf+Ztw4JMArS6racbm
5jsdoqcPsbI2bLhJB5La0iXGdmK4+SVS/MhGbHD5zzHWopNUR4UsTp6y2Hh5UcrQ
d+b3GQQeoIW0Vm+25/Vz2hisbclfpfnDC8d6x4M4kusekALx+expNQjiufbjpx7X
6gU1IWOV7cbFBb/V+4bwMU+gsF35SPYPgKqj9/nmZZG6Bd38UXRfCQOfEfG+OCFx
KWQDARlxHeHOlahgOW6yaVmoampau1tiprycZ556kKPsYBk15MsAG/9/BQuA+bjD
TeOH6HiLrlZI57PbyQ6uuWyh2ouZgo9ShMUO5euqc/qR2ig=
-----END CERTIFICATE-----
Serial Number: 04:01:09:F2:6D:38:DA:A7:34:70:B3:A9:56:11:F3:59:2B:46
Common Name: test.oregonnexus.org
Issuer CN: Let's Encrypt Authority X3
Issuer Country: US
Issuer Org: Let's Encrypt
Version: 3
not before: 20200807155801
Unknown Field: 15:58:01 07-08-2020
not after: 20201105145801
Unknown Field: 14:58:01 05-11-2020
pub key alg: 1.2.840.113549.1.1.1
signature algorithm: 1.2.840.113549.1.1.11
Unknown Field: 0382010F003082010A0282010100CE124744393E8A314C683F5244EEE8266091EBD03958D8163E7DA34BC65548090568CCBDDF77CF51B84691AA77C7570B09B4FCA631682CEE66104C835C64914C6F19AFFBF0D2826ED2910130E2C4150DBC346BC5B10F29D1C15FB74ED4162C26626F30B0A24C8BF6E40CE00E90CC3F8CD760EC9A528818942F210825F700BAD0A21DA52713615828A54693BF13ACBF0BEF9C7EA43726450DD04C3BF176994AFA3EF2074FEC01810BB65A9569F380F44908563903272DA4F068758E80B2379BE3096AA8811EF937BCC1FF4066514F76436626D14C9D325B16D8605649DBAD5E066B8029AC30F636994D157FF37C50E755032F1B47066226964F268ECC1119E4650203010001
Unknown Field: 2048
Unknown Field: 3116A43DCEB100F12D4B65D57C404C53
Unknown Field: 1.2.840.113549.2.5
Unknown Field: 159186356B3B7AB69144E2B6E37F80E38D355635
Unknown Field: 134A604CC71B56AB71B81F708B3DB6D730D2C1BC63BD7CD29CF78F40563A2ADF
Unknown Field: 5
Unknown Field: test.oregonnexus.org
Unknown Field: 0
Unknown Field: 1.3.6.1.5.5.7.3.2
Unknown Field: 1.3.6.1.5.5.7.3.1
Unknown Field: 1.3.6.1.4.1.44947.1.1.1
Unknown Field: 2.23.140.1.2.1
Unknown Field: http://ocsp.int-x3.letsencrypt.org

Protocol Used: TLS Version 1.2
http_persist_req(POST) entered.
http_long_ParseURL(): entered
http_long_ParseURL(): entered
do_oper(POST): entered
There are 0 cookies in the cache
POST /EdFi.Ods.WebApi.LBL_3_1_1/data/v3/ed-fi/schools HTTP/1.1
Host: test.oregonnexus.org
User-Agent: http-api/1.39
Content-Type: application/json
Content-Length: 943
accept:application/json
authorization:Bearer 9c90228af1fd44b59b9626e23d3600a6


senddoc(): entered
{"id":"","addresses":[{"addressTypeDescriptor":"uri://ed-fi.org/AddressTypeDescriptor#Physical","stateAbbreviationDescriptor":"uri://ed-fi.org/StateAbbreviationDescriptor#OR","city":"ALBANY","postalCode":"97321","streetNumberName":"3122 MADISON ST SE"}],"educationOrganizationCategories":[{"educationOrganizationCategoryDescriptor":"uri://ed-fi.org/EducationOrganizationCategoryDescriptor#School"}],"gradeLevels":[{"gradeLevelDescriptor":"uri://ed-fi.org/GradeLevelDescriptor#Kindergarten"},{"gradeLevelDescriptor":"uri://ed-fi.org/GradeLevelDescriptor#First grade"},{"gradeLevelDescriptor":"uri://ed-fi.org/GradeLevelDescriptor#Second grade"},{"gradeLevelDescriptor":"uri://ed-fi.org/GradeLevelDescriptor#Third grade"},{"gradeLevelDescriptor":"uri://ed-fi.org/GradeLevelDescriptor#Fourth grade"},{"gradeLevelDescriptor":"uri://ed-fi.org/GradeLevelDescriptor#Fifth grade"}],"schoolId":0640,"nameOfInstitution":"Test-002/120 LAFAYETTE ELEMENT"}
recvresp(): entered
HTTP/1.1 200 OK
ETag: "5249019594662531255"
Location: https://test.oregonnexus.org/EdFi.Ods.WebApi.LBL_3_1_1/data/v3/ed-fi/schools/8c67f8ac7e554d6895ad18ff741a0f3b
Strict-Transport-Security: max-age=31536000
Date: Fri, 21 Aug 2020 18:57:54 GMT
Content-Length: 0


SetError() #13: HTTP/1.1 200 OK
recvresp(): end with 200
recvdoc parms: identity 0
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
recvdoc(): Receiving 0 bytes.
recvdoc(): Nothing to receive, exiting...
http_close(): entered

 

CURL response:

 

--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi

-- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi