PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → json problem
json problem
Débuté par Lasse Sandström, 14 aoû. 2022 07:59 - 3 réponses
Membre enregistré
19 messages
Posté le 14 août 2022 - 07:59
Hi,

there is how to I get token form maventa in Finland:

INTERNAL PROCEDURE MaventaAuth()
sJson.client_id = sClientID
sJson.client_secret = sClientPASS
sJson.vendor_api_key = sVendorAPI
sJson.grant_type = "client_credentials"
sJson.scope = "eui"
sRestReq.Method = httpPost
sRestReq.URL = sURL + "oauth2/token"
sRestReq.ContentType = typeMimeJSON
sRestReq.Content = sJson
sRestRes = RESTSend( sRestReq )
END

And there comes this:

{"access_token":"eyJ0eXAiOiJKV1QiLCJraWQiOiIyZGZjYTlmMTE4ZWRlNThmYmZiMjM0ZTIxZDQ0MTY1ODVjNzc3NjZjMDY4OTk4MDdkYTgwNTlhMTRmODRlNjgyIiwiYWxnIjoiUlM1MTIifQ.eyJpZGVudGl0eSI6InVzZXIiLCJ1c2VyX2lkIjoiMTEyYTUzM2YtYjgzNS00ZTQzLTgzMjYtNzNjOWY3ODhjYzkyIiwiY29tcGFueV9pZCI6Ijg3NzI3MzUyLWU3MjEtNGRlNi1iYzY4LWI2YmI5YWQwZTA1ZiIsInNjb3BlIjpbImV1aTpvcGVuIiwiY29tcGFueTpyZWFkIiwiY29tcGFueTp3cml0ZSIsImxvb2t1cCIsInJlY2VpdmFibGVzOmFzc2lnbm1lbnRzIiwiZG9jdW1lbnQ6c2VuZCIsImRvY3VtZW50OnJlY2VpdmUiLCJpbnZvaWNlOnJlY2VpdmUiLCJpbnZvaWNlOnNlbmQiLCJhbmFseXNpcyJdLCJ2ZW5kb3JfaWQiOiJkMjlhZDgwYy0zYzM3LTRkNjAtOTc3MS0wYzkxZDdjYWZmNzIiLCJleHAiOjE2NjA0NTk3NTB9.DQAYSYsAAFHnkZvbRBm35yEhf02idTnBKjqc4Ldg9vhfNHE4DoGXp4bz6Qf4JlSkCja40HANz5wkRDgNsT_uINkek3-MIRa5HRcs256Rc-lWa9oy1vKsZFtyYMbUkF_vCqUd0t8v_conrNHJwnw6hoDS-vp3vd43dm-vRUXko6optu4amGNXnbJ_CD3rfdAJHFYFeHX8GaURdBUKUAglXZlHRiqk9zbyc0xbvIZNgqgvlKt-g7vTZkn-0P8QwMYpPNLKn5ic1KREwfM77p1wy902qNfYrXV2KgvXQfJxXJ4zjT5MXZf_XGnUP3H-cki870HMx_yi_B0aqBdDlINRbw","token_type":"bearer","expires_in":3600,"scope":"eui"}

This is right, but how I put this in next:

INTERNAL PROCEDURE MaventaInvoiceSend()
sRestReq.Header[ "file" ] = fLoadText( "C:\erpKasoori\FinvoiceXML\20220208_1_Testiasiakas_Finvoice.xml" )
sRestReq.Header[ "format" ] = "--" // "FINVOICE30"
sRestReq.Header[ "recipient_type" ] = "b2b"
sRestReq.Header[ "recipient_operator" ] = "003721291126"
sRestReq.Header[ "disabled-routes" ] = "--"
sRestReq.Header[ "route_order" ] = "--"
sRestReq.Method = httpPost
sRestReq.URL = sURL + "v1/invoices"
sRestReq.AuthToken = sAuth
sRestReq.ContentType = typeMimeJSON
sRestRes = RESTSend( sRestReq )
END

this token is in sAuth variable, and does not work, what is way to put this token to
sRestReq.AuthToken = sAuth


br Lasse S
Membre enregistré
19 messages
Posté le 25 août 2022 - 07:43
Need some help for this!
Membre enregistré
794 messages
Popularité : +40 (42 votes)
Posté le 25 août 2022 - 20:18
Hi. According to the help (https://doc.windev.com/en-US/…), the parameter in which you pass the token is called "access_token" by default. Is that the name the API expects? If it is not correct you should define the parameter yourself.

Rubén
Membre enregistré
58 messages
Popularité : +6 (6 votes)
Posté le 26 août 2022 - 10:06
Hi Lasse,
I think your request need the token like that :
sRestReq.Header["access_token"] = "bearer ###ALL THE CONTENT OF ACCESS_TOKEN###"

Many API use this syntax.

--
Qui ne sait rien, de rien ne doute...