Welcome! Log In Create A New Profile

Advanced

json problem

Posted by LasseS 
json problem
August 14, 2022 07:58AM
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
Re: json problem
August 25, 2022 07:49AM
Need some help!
Re: json problem
September 09, 2022 10:40AM
Hi Lasse

You need to add the received bearer token in the header of your restrequest.
Like this:
sRestReq.Header[ "Authorization" ] = "Bearer "+received access token

That should do the trick.
Tip 1: Use Postman to test your REST API flows.
Tip 2: Access Tokens expire so if you are using REST API's throughout the day you should validate before every request if your Bearer token is still valid (<> expired) and if not, get a new one first.

Cheers

Peter Holemans
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: