PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV 2024
→
API (REST) Request
API (REST) Request
Started by Kim O'Regan, Dec., 05 2019 11:32 AM - 6 replies
Connect yourself…
Kim O'Regan
#1
Posted on December, 05 2019 - 11:32 AM
Hi all,
I'm trying to figure out how to create an API-request in Windev.
The request looks like this:
<?xml version='1.0' encoding='ISO-8859-1'?>
<marathon>
<password>abc123</password>
<type>api_operation</type>
<company_id>ABC</company_id>
<employee_id>ABC123</employee_id>
<date>2019-12-04</date>
<repeat_until></repeat_until>
<client_id>ABC</client_id>
<project_no>123</project_no>
<feecode_id>123</feecode_id>
<hours>4,5</hours>
<full_time_percentage></full_time_percentage>
<comment>ABC-1234 Working</comment>
</marathon>
Which is posted to:
"
https://adress_of_webservice
"
How would I do this in Windev?
Thankful for any help
Regards
/Kim
Report
0
0
Jeroen de Jonge
#2
Posted on December, 05 2019 - 1:01 PM
Try this:
s
Xml
is string
= [
<?xml version='1.0' encoding='ISO-8859-1'?>
<marathon>
<password>abc123</password>
<type>api_operation</type>
<company_id>ABC</company_id>
<employee_id>ABC123</employee_id>
<date>2019-12-04</date>
<repeat_until></repeat_until>
<client_id>ABC</client_id>
<project_no>123</project_no>
<feecode_id>123</feecode_id>
<hours>4,5</hours>
<full_time_percentage></full_time_percentage>
<comment>ABC-1234 Working</comment>
</marathon>
]
Req
is httpRequest
c
Req.URL
=
https
:
//adress_of_webservice"
c
Req
..
ContentType
=
"application/xml"
//or "text/xml"
c
Req
..
Method
=
httpPost
c
Req
..
Content
=
s
Xml
//cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
c
Resp
is httpResponse
=
HTTPSend
(
c
Req
)
SWTICH
c
Resp
..
StatusCode
CASE
200
//OK
OTHER
CASE
//cResp..Content contains more info
END
Report
0
0
Kim O'Regan
#3
Posted on December, 05 2019 - 3:13 PM
Hi and thanks for the answer Jeroen.
Your example worked when I put in the XML-request in the sXml brackets.
The "problem" is that I will be reading rows from a database and sending them with httpPost.
So some of the values has to be variables. How do I achieve that?
Functioning:
sXml is string = [
<?xml version='1.0' encoding='ISO-8859-1'?>
<marathon>
<password>abc123</password>
<type>api_operation</type>
<company_id>ABC</company_id>
<employee_id>ABC123</employee_id>
<date>2019-12-04</date>
<repeat_until></repeat_until>
<client_id>ABC</client_id>
<project_no>123</project_no>
<feecode_id>123</feecode_id>
<hours>4,5</hours>
<full_time_percentage></full_time_percentage>
<comment>ABC-1234 Working</comment>
</marathon>
]
cReq is restRequest
cReq.URL = "
https://webservice_server
"
cReq..ContentType = "application/xml" //or "text/xml"
cReq..Method = httpPost
cReq..Content = sXml
//cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
cResp is restResponse = HTTPSend(cReq)
Regards
/Kim
Report
0
0
Jeroen de Jonge
#4
Posted on December, 06 2019 - 2:20 PM
Try this:
xmlDoc
is xmlDocument
xmlDoc
..
Encoding
=
XMLEncodingUTF8
xmlDoc.marathon.password
=
"abc123"
xmlDoc.marathon.type
=
"api_operation"
xmlDoc.marathon.company_id
=
"ABC"
xmlDoc.marathon.employee_id
=
"ABC123"
xmlDoc.marathon.date
=
"2019-12-04"
xmlDoc.marathon.repeat_until
=
""
xmlDoc.marathon.client_id
=
"ABC"
xmlDoc.marathon.project_no
=
123
xmlDoc.marathon.feecode_id
=
123
xmlDoc.marathon.hours
=
4.5
xmlDoc.marathon.full_time_percentage
=
""
xmlDoc.marathon.comment
=
"ABC-1234 Working"
c
Req
is httpRequest
c
Req.URL
=
"https://adress_of_webservice"
c
Req
..
ContentType
=
"application/xml"
//or "text/xml"
c
Req
..
Method
=
httpPost
c
Req
..
Content
=
XMLBuildString
(
xmlDoc
,
XMLDocumentDefault
)
//cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
c
Resp
is httpResponse
=
HTTPSend
(
c
Req
)
SWITCH
c
Resp
..
StatusCode
CASE
200
//OK
OTHER
CASE
//cResp..Content contains more info
END
Report
0
0
Kim O'Regan
#5
Posted on December, 06 2019 - 4:46 PM
Hi and thanks for the answer, again, Jeroen!
I will try this.
/Kim
Report
0
0
Kim O'Regan
#6
Posted on December, 09 2019 - 4:36 PM
Hi Jeroen,
I get this when running the script:
"Failure retrieving the XML.
unknown encoding 2
.content"
Tried the "text/xml" to no prevail.
The Content seems to be empty.
What's missing?
Regards
/Kim
Report
0
0
Kim O'Regan
#7
Posted on December, 10 2019 - 7:01 PM
Hi,
I've managed to implement the XML-part into my application. So now it sends and stores the info in the database.
I do though have a "small" problem. I use time in my application which is formatted hh:mm.
The recieving system use either hh,mm or hh.mm and, e.g 1:30 is displayed 1,5 or 1.5 on the recieving system.
How do I convert e.g 1:30 to 1,5?
Regards
/Kim
Report
0
0
→ Go back to WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text