About Json Post with Auth.

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 9, 2018
Company: ÖTÜKEN TEKNOLOJİ ARAŞTIRMA GELİŞTİRME EĞİTM HİZMETLERİ TİCARET LİMİTED ŞİRKETİ

Hello. I have a question.
I want to post json. It contains user information. I want to read the returned Json data.

example url : "api.abc.com/getlist/"

jsoninput = {  
         
              "MERCHANT":"merchid",
              "MERCHANT_KEY":"merchkey",
              "START_DATE":"2022-01-01",
              "END_DATE":"2022-02-02"
           
        }


My Code :

       ServerAdress = "api.abc.com";
Resource = "getlist";
ssl1 = new OpenSSLSecureConnection(Undefined, Undefined);
HTTP = New HTTPConnection(ServerAdress,443,,,,10,ssl1);


HTTPRequest = New HTTPRequest("getlist");
HTTPRequest.Headers.Insert("Authorization", jsoninput);
HTTPRequest.Headers.Insert("Accept",  "application/json");
       HTTPRequest.Headers.Insert("Content-Type","application/x-www-form-urlencoded");
       HTTPRequest.Headers.Insert("Accept-Language",  "en_US");
       HTTPRequest.Headers.Insert("Cache-Control",    "no-cache");
       HTTPRequest.SetBodyFromString("grant_type=client_credentials");
Connection = New HTTPConnection("api.abc.com",,,,,10,New OpenSSLSecureConnection);

       JSONReader = New JSONReader;
 
Try        
           HTTPAnswer = Connection.Post(HTTPRequest); // post Request
           JSONReader.SetString(HTTPAnswer.GetBodyAsString());
       Data = ReadJSON(JSONReader, False);
           message(Data);
       Except
   ErrorText = "Sending " + ErrorDescription();
   message(ErrorText);
EndTry;

 
#2
People who like this:0Yes/0No
Administrator
Rating: 14
Joined: Oct 3, 2019
Company:

Hello Erdoğan,

and what is your question?

 
#3
People who like this:0Yes/0No
Just came
Rating: 1
Joined: May 9, 2018
Company: ÖTÜKEN TEKNOLOJİ ARAŞTIRMA GELİŞTİRME EĞİTM HİZMETLERİ TİCARET LİMİTED ŞİRKETİ

I am very sorry. I forgot to write my question. There is an Api service. I want to post a value here. The json information contains login information. Webservice url: "api.abc.com/getlist/". I want to send this as a parameter. I want to read the returned value as json.

jsonparameters= '{
       
              "MERCHANT":"merchid",
              "MERCHANT_KEY":"merchkey",
              "START_DATE":"2022-01-01",
              "END_DATE":"2022-02-02"
         
        }'

 
#4
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Oct 5, 2018
Company:

Hi Erdoğan Uğuz .
If I understand you correctly you need to put parameters into the request body. But you have another value there.
HTTPRequest.SetBodyFromString("grant_type=client_credentials");
You can do something like this
HTTPRequest.SetBodyFromString(jsonparameters);
Then maybe to add parameter grant_type to your json ?

 
#5
People who like this:0Yes/0No
Administrator
Rating: 14
Joined: Oct 3, 2019
Company:

Hello Erdoğan,

I saw your question on stackoverflow.

Please email me the documentation for this service, and I'll try to help you

 
Subscribe
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.