trying to use a web service (API)

Started by claude, September 09, 2025, 12:18:59 PM

Previous topic - Next topic

claude

Hello everyone, we have a Linux server running Pxplus 11.50.  We're trying to use a web service (API) to issue digital invoices. Since it's somewhat complex and it doesn't work. We're trying a simpler API, but it doesn't work either. When we use the POSTMAN program, it works fine, from the same server.

With POSTMAN
Command: GET https://cataas.com/api/count

Body:
{
"id": "string",
"tags": [
"string"
],
"mimetype": "string",
"createdAt": "string"
}

Response Received:
{"count":1987}


With PxPlus

The test program is as follows:

10 CLOSE (1); OPEN (1)"json3.txt"
20 LET JSON1$=""
30 READ RECORD (1,END=0060)JSON1_AUX$
40 LET JSON1$+=JSON1_AUX$
50 GOTO 0030
60 CLOSE (1)
70 PRINT JSON1$
80 LET A8$="GET"
90 REM -------------A2$="{"+CHR(34)+"User"+CHR(34)+":"+CHR(34)+"kqcorfelofxx_tfhka" +CHR(34)+","+CHR(34)+"Password"+CHR(34)+": "+CHR(34)+";xxxxxxxxx"+CHR(34)+"}"
100 LET A2$=JSON1$
110 CALL "*plus/web/request","https://cataas.com/api/count",A2$,A3$,A4$,A5$,A6$,A7$,A8$,A9



The program output is as follows (Both on the Server and on a Windows PC):

->run
{"id": "string","tags": ["string"],"mimetype": "string","createdAt": "string"}
0110 CALL "*plus/web/request","https://cataas.com/api/count",A2$,A3$,A4$,A5$,A6
0110:$,A7$,A8$,A9
Cannot contact host server
1>


Please can you guide us to use the web service (API) from Pxplus?

Thank you very much and greetings

Claude H.

Loren Doornek

With a GET command, you usually don't pass it any data since it is just GETting something. Passing data to the API usually uses a POST or PUT.

This simple call works for me:

CALL "*plus/web/request","https://cataas.com/api/count",$$,recvdata$
PRINT RECVDATA$

{"count":1987}

Stéphane Devouard

Hi

As pointed out by Loren, no data needs to be passed in when you use the GET verb

The minimal parameters for *plus/web/request are
- the URL
- the data to pass to the webservice, "" for a GET
- the response data received
- the reponse headers received

->call "*plus/web/request","https://cataas.com/api/count","",respd$,resph$
->?respd$
{"count":1987}
->?resph$
HTTP/1.1 200 OK
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Au
thorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Content-Size: 14
Content-Type: application/json
Date: Wed, 10 Sep 2025 09:12:24 GMT
Set-Cookie: __Host-SESSION_ID=858e3b05-3cf7-42f0-95f0-38feecd9e442; Path=/; Secu
re; HttpOnly; SameSite=Strict
Connection: close
content-length: 14

->

This webservice returns JSON data, you can use the JSON interface built-in PxPlus to parse and use the data returned

->dim load data$=respd$
->dump
! ERR=42, CTL=0, RET=2
! **********************************************************
! Level=1
! PGN="<Unsaved>"
DATA$["count"]="1987"
RESPD$="{""count"":1987}"
RESPH$="HTTP/1.1 200 OK"+$0A$+"Access-Control-Allow-Headers: X-Requested-With, C
ontent-Type, Accept, Origin, Authorization"+$0A$+"Access-Control-Allow-Methods:
GET, POST, PUT, DELETE, OPTIONS"+$0A$+"Access-Control-Allow-Origin: *"+$0A$+"Con
tent-Size: 14"+$0A$+"Content-Type: application/json"+$0A$+"Date: Wed, 10 Sep 202
5 09:12:24 GMT"+$0A$+"Set-Cookie: __Host-SESSION_ID=858e3b05-3cf7-42f0-95f0-38fe
ecd9e442; Path=/; Secure; HttpOnly; SameSite=Strict"+$0A$+"Connection: close"+$0
A$+"content-length: 14"+$0A$
! ----
! Global variables (%...)
->

You then do whatever you want with the data$[] associative array / hash table

Hope this helps

Stéphane Devouard
Portfolio | Work

claude


Hello everyone,

Thank you very much. We've resolved the issue. The variable a9 was set to zero, and the connection failed due to a timeout.

Regards