Consuming REST API - String "HTTP/1.1"

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
sandrocarosso
Posts: 7
Joined: Mon Dec 05, 2022 1:58 pm

Consuming REST API - String "HTTP/1.1"

Post by sandrocarosso »

Hello, I have to consume a REST web services that responds to this link:
https://export-api-staging.lorch.cloud/ ... /weldseams? from_start_time_utc=1640993522&to_start_time_utc=1658323083".
I should consume it in GET so that it returns a JSON containing the requested information.
From what I can see from debugging, the request is done like this:
GET /api/export/weldseams?from_start_time_utc=1640993522&to_start_time_utc=1658323083 HTTP/1.1.
The REST web services tells me: HTTP/1.1 422 Unprocessable Entity.

How can I prevent "HTTP/1.1" from appearing at the bottom of my request?
Thank you
Scott Klement
Site Admin
Posts: 719
Joined: Sun Jul 04, 2021 5:12 am

Re: Consuming REST API - String "HTTP/1.1"

Post by Scott Klement »

Sorry, what are you coding to get the result you are seeing?
sandrocarosso
Posts: 7
Joined: Mon Dec 05, 2022 1:58 pm

Re: Consuming REST API - String "HTTP/1.1"

Post by sandrocarosso »

Good evening Scott,
thanks for your reply.
This is the command the API provider sent to me (he specified that I can also use "Application/json")

Code: Select all

curl -X GET -H "X-Api-Key: 2KTV8VRAiUk-tvh7TyS_tf6t5qHSo3qAlWySDrHBC3o" -H "Accept: text/csv" "https://export-api-staging.lorch.cloud/api/export/weldseams? from_start_time_utc=1640993522&to_start_time_utc=1658323083"
I try to post what I coded to get the result that I am attaching.
This is what I get from debugging:

Code: Select all

HTTPAPI Ver 1.45 released 2021-09-20
NTLM Ver 1.4.0 released 2014-12-22
OS/400 Ver V7R4M0

New iconv() objects set, PostRem=819. PostLoc=0. ProtRem=819. ProtLoc=0
http_persist_open(): entered
http_long_ParseURL(): entered
DNS resolver retrans: 2
DNS resolver retry  : 2
DNS resolver options: x'00000136'
DNS default domain: CORAL.eu
DNS server found: 10.0.0.1
DNS server found: 10.0.0.2
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
TLS version 1.3 support enabled
initializing GSK environment
GSK Environment now available
-------------------------------------------------------------------------------------
Dump of local-side certificate information:
-------------------------------------------------------------------------------------
Nagle's algorithm (TCP_NODELAY) disabled.
SNI hostname set to: export-api-staging.lorch.cloud
-------------------------------------------------------------------------------------
Dump of server-side certificate information:
-------------------------------------------------------------------------------------
Cert Validation Code = 6000
-----BEGIN CERTIFICATE-----
MIIFfzCCBGegAwIBAgIQDWbopKNjOnkJlGS8WMMblTANBgkqhkiG9w0BAQsFADBG
MQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExM
QzETMBEGA1UEAxMKR1RTIENBIDFENDAeFw0yMzA1MTUwMDA1MzdaFw0yMzA4MTMw
MDU3NDlaMCkxJzAlBgNVBAMTHmV4cG9ydC1hcGktc3RhZ2luZy5sb3JjaC5jbG91
ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKgELC0K1BphG/4Z1xnz
GB8OytUl0udItuqfJeDeIp6eRG1SAqBPkNUXmBLzhhBA5HhOD/uPt3J56bBwgVHh
Yc8CFmWjHFSHhv8KDF+pvWXbXZ8FWPSULRQMF+I6vREnAkmwOy2m++o92njEJ2Hv
EVWgLVd945gzPnUnHjq+4QRsWjmXV7dIM2SLT8UCdQFJDfH5lfUZCZZY2psP9oyp
TC5oibN57Rfyu5uaDnXVfN032yMhU+UvPaTWP/k9SNTISiic5dwAb5ZjVS/KoLOc
3QG4RdH5q0LmRDf0KIiYZfiZhb8syUUJhMSDgTVmh19TVzdl2NFJmEBzutrrH9dS
boUCAwEAAaOCAoQwggKAMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUEDDAKBggrBgEF
BQcDATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTVPUgdeiavrkZFyiErRHLtL+Xf
/DAfBgNVHSM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jH+7GYJ1tez+ZgQambSs1tXz
jQ7E+nWPQNc2P8Iba1CKiLUkPw==
-----END CERTIFICATE-----
Serial Number: 0D:66:E8:A4:A3:63:3A:79:09:94:64:BC:58:C3:1B:95
Common Name: export-api-staging.lorch.cloud
Issuer CN: GTS CA 1D4
Issuer Country: US
Issuer Org: Google Trust Services LLC
Version: 3
not before: 20230515020537
Unknown Field: 02:05:37 15-05-2023
not after: 20230813025749
Unknown Field: 02:57:49 13-08-2023
pub key alg: 1.2.840.113549.1.1.1
signature algorithm: 1.2.840.113549.1.1.11
Unknown Field: 0382010F003082010A0282010100A8042C2D0AD41A611BFE19D719F3181F0ECAD525D2E748B6EA9F25E0DE229E9E446D5202A04F90D5179812F3861040E4784E0FFB8FB77279E9B0708151E161CF021665A31C548786FF0A0C5FA9BD65DB5D9F0558F4942D140C17E23ABD11270249B03B2DA6FBEA3DDA78C42761EF1155A02D577DE398333E75271E3ABEE1046C5A399757B74833648B4FC5027501490DF1F995F519099658DA9B0FF68CA94C2E6889B379ED17F2BB9B9A0E75D57CDD37DB232153E52F3DA4D63FF93D48D4C84A289CE5DC006F9663552FCAA0B39CDD01B845D1F9AB42E64437F428889865F89985BF2CC9450984C483813566875F53573765D8D149984073BADAEB1FD7526E850203010001
Unknown Field: 2048
Unknown Field: 0B294732F59C896A181A6823C8D9F49A
Unknown Field: 1.2.840.113549.2.5
Unknown Field: 310C04285FD3EAC8D9EA39D7841DC145C221BACC
Unknown Field: 3ABCDA6516318C1DB06C9BA636566166F25AC088A1E96BD19034036713216B91
Unknown Field: 5
Unknown Field: export-api-staging.lorch.cloud
Unknown Field: 0
Unknown Field: 1.3.6.1.5.5.7.3.1
Unknown Field: 1.3.6.1.4.1.11129.2.5.3
Unknown Field: 2.23.140.1.2.1
Unknown Field: http://ocsp.pki.goog/s/gts1d4/oHtGNeU1x-c

Protocol Used: TLS Version 1.3
http_persist_req(GET) entered.
http_long_ParseURL(): entered
http_long_ParseURL(): entered
do_oper(GET): entered
There are 0 cookies in the cache
GET /api/export/weldseams?from_start_time_utc=1640993522&to_start_time_utc=1658323083 HTTP/1.1
Host: export-api-staging.lorch.cloud
User-Agent: http-api/1.45
X-API-KEY: oQdEmSAq8_Auo38bHmR2ulRifusIAKGpeAJgfsRiqcw


recvresp(): entered
HTTP/1.1 422 Unprocessable Entity
Date: Sat, 20 May 2023 17:50:15 GMT
Content-Length: 0
Via: 1.1 google
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000


SetError() #13: HTTP/1.1 422 Unprocessable Entity
recvresp(): end with 422
recvdoc parms: identity 0
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
recvdoc(): Receiving 0 bytes.
recvdoc(): Nothing to receive, exiting...
SetError() #13: HTTP/1.1 422 Unprocessable Entity
http_close(): entered
This is the code I use

Code: Select all

  // Generate the JSON document to send                                                    
                                                                                                    
           http_debug(*on: '/lorch/log/wsmes0.txt');                                                
           $Apikey='oQdEmSAq8_Auo38bHmR2ulRifusIAKGpeAJgfsRiqcw';                                   
                                                                                                    
           http_xproc( HTTP_POINT_ADDL_HEADER                                                       
                           : %paddr(addSpecialHeaders)                                              
                           : %addr($Apikey) );                                                      
                                                                                                    
           url = 'https://export-api-staging.lorch.cloud/api/'+                                     
                 'export/weldseams?from_start_time_utc='+                                           
                  %Trim(inizio)+                                                                    
                  '&to_start_time_utc='+                                                            
                  %Trim(fine);                                                                      
           monitor;                                                                                 
               rc = http_req('GET': %trim(url): *omit: Response: *omit:                             
                    request: *omit);                                                                
           on-error;                                                                                
              httpcode = http_error();                                                              
              dsply httpcode;                                                                       
           endmon;                                                                                  
           If 1=2;                                                                                  
           DATA-INTO result %DATA(response:'case=convert allowextra=yes')                           
                            %PARSER('YAJLINTO');                                                    
           Endif;                                                                                   
           end-proc;                                                                                
           // ===========================================================                           
           Dcl-Proc addSpecialHeaders;                                                              
              Dcl-Pi *N;                                                                            
                 headersToAdd    Varchar(32767);                                                    
                 var             like($Apikey) const;                                               
              End-Pi;                                                                               
                                                                                                    
              Dcl-c  CRLF  x'0d25';                                                                 
                                                                                                    
              headersToAdd = 'X-API-KEY: ' + var + CRLF;                                            
                                                                                                    
           End-Proc;                                                                                
      /end-free                                                                                     
Thank you for the support you can provide me

Sandro
jonboy49
Posts: 220
Joined: Wed Jul 28, 2021 8:18 pm

Re: Consuming REST API - String "HTTP/1.1"

Post by jonboy49 »

Did you actually try that curl request? Because when I try it I get the same basic error that you are seeing in your code.
Scott Klement
Site Admin
Posts: 719
Joined: Sun Jul 04, 2021 5:12 am

Re: Consuming REST API - String "HTTP/1.1"

Post by Scott Klement »

Sandro,

422 Unprocessable Content means that the request entity (the headers and data you sent) was a valid syntax, but it was unable to process the request for some reason. (It does not explain further than that.)

Here are some things I noticed, though:
  • The curl example sets the 'Accept' header to text/csv. You are not doing that.
  • The curl example sets the "X-Api-Key:" header, but you've provided "X-API-KEY:". I don't know if the upper/lower case matters to the server.. but it's possible? I don't see why you wouldn't make them match??
I did not try it, but according to Jonboy the curl example doesn't work, either. Something isn't right, here...

I don't see anything wrong with the "HTTP/1.1" as you said in an earlier post. This HTTP version is a part of the HTTP protocol, and is required -- removing it would make the request completely invalid.
sandrocarosso
Posts: 7
Joined: Mon Dec 05, 2022 1:58 pm

Re: Consuming REST API - String "HTTP/1.1"

Post by sandrocarosso »

Thanks everyone for the suggestions!! I also entered "Accept: application/json" and now the webservice returns me the data I need, in addition to the corrections you suggested.

Thank you all
Post Reply