FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV 2024
→
API (REST) Request
API (REST) Request
Débuté par Kim O'Regan, 05 déc. 2019 11:32 - 6 réponses
Connectez-vous…
Kim O'Regan
#1
Posté le 05 décembre 2019 - 11:32
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
Signaler
0
0
Jeroen de Jonge
#2
Posté le 05 décembre 2019 - 13:01
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
Signaler
0
0
Kim O'Regan
#3
Posté le 05 décembre 2019 - 15:13
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
Signaler
0
0
Jeroen de Jonge
#4
Posté le 06 décembre 2019 - 14:20
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
Signaler
0
0
Kim O'Regan
#5
Posté le 06 décembre 2019 - 16:46
Hi and thanks for the answer, again, Jeroen!
I will try this.
/Kim
Signaler
0
0
Kim O'Regan
#6
Posté le 09 décembre 2019 - 16:36
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
Signaler
0
0
Kim O'Regan
#7
Posté le 10 décembre 2019 - 19:01
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
Signaler
0
0
→ Revenir à WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte