cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass the body content which is in Json format in Rest API's Post method?

former_member187060
Participant

Hi Experts,

We are building a connector with markto and SAP C4C by using the REST API's and i have some queries regarding the ABSL.

1. How to pass the Body content in the post method of the API in Json format?

2. And how to parse the response that is in JSON format string?

Below are some screen shots.

Body Should be in Below Json Format how to send it through our ABSL?

Below is the response we get in Json format(Requested the API from online Tool).

How to parse this response in ABSL.

Kindly help me in this issue.

Regards,

Siraj.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member186648
Active Contributor
0 Kudos

Do string concatenation:

var Body = "{" +
"action" + ":" + "createOnly" + ","+
...

+ "}";

former_member187060
Participant
0 Kudos

Hi Pradeep,

Thanks for the reply,

I have already tried this but getting error  like below.

[ code":"609","message":"Unexpected character ('a' (code 97)): was expecting double-quote to start field name]

system not accepting the string format body it takes only elements in double quotes not complete string.

Any other idea appreciate your help.

Thanks,

Siraj.

former_member186648
Active Contributor
0 Kudos

It accepts string format.

Try this, in the debugger after the assignmet of variable "Body" , get the content of this variable
and check if everything is correct, and then proceed.

May be you can place the content is other tool to verify if it is correct.

Thanks, Pradeep.

former_member187060
Participant
0 Kudos

Hi Pradeep,

Below are the screen shots of request and response the JSON body is exact what you have said.

Body content .

Body content in Debugger.

Error Reposne.

Kindly help in this issue.

Regards,

Siraj.

Former Member
0 Kudos

Hi,

In JSON format, string values must be encapsulated with double quotes.

In your example, this is how you would construct the beginning of your body object:


Body = "{ \"action\" : \"updateonly\" , ...

The  \" notation allows you to insert a double quote inside a string.

former_member187060
Participant
0 Kudos

Hi Florence,

Thanks for your helpful reply,

I have done exactly what you have said and got success..

can you please tel me how can i pass the parameters in the JSON string like i have email address name i need to pass it dynamically not as hard coded.

Because in JSON it accepting the input field values should also be in double quotes.

I have done as below and its working fine but how to pass the parameters dynamically.

Kindly help.

Thanks,

Siraj.

former_member186648
Active Contributor
0 Kudos

Ex: "email\":\""++"\",

former_member187060
Participant
0 Kudos

Hi Pradeep Kumar,

Thanks for your helpful reply,

Can you please help me in parsing the JSON format string which i'm getting in response for any GET method request to the REST API.

Below is the response.

Appreciate your help.

Thanks,

Siraj.

Former Member
0 Kudos

Hi Mohid,

Take a free variable of type "Text" and pass the response content into this variable, here this variable will be our response and using a custom library build your parser function for parsing this response

Mostly you need to use your String functionalities for Parsing and DeParsing the responses.

Here below is the ex for your reference

var response : Text;

if (ws_call.Code.Contains("200"))

    {

            response.content = ws_call.Content;

            var result = "YOUR PARSER LIB FUNCTION"; (Pass the response as a parameter)

     }

*************Lib Function Building using string functionalities************

var text = Response.content;

var textLen = text.Length();

if (!text.IsInitial())

{

    var respcode;

    var stat = text.Find("respstat");

    if (!stat.IsInitial())

    {

        var start = stat + 11;

        //var end = stat+13;

        respcode = text.Substring(start, 1);

        result = result.Concatenate(respcode) + "|";

    }

    var mess = text.Find("resptext");

    if (!mess.IsInitial())

    {

        var start = mess + 11;

        var end = text.Find("\"", start);

        var delimtLen = end - start;

        var resptext = text.Substring(start, delimtLen);

        result = result.Concatenate(resptext);

    }

    if (respcode == "A")

    {

        var token = text.Find("token");

        if (token > 0)

        {

            var start = token + 8;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

        var profileid = text.Find("profileid");

        if (profileid > 0)

        {

            var start = profileid + 12;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

        var acctid = text.Find("acctid");

        if (acctid > 0)

        {

            var start = acctid + 9;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

        var amount = text.Find("amount");

        if(amount > 0)

        {

            var start = amount + 9;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

        var retref = text.Find("retref");

        if (retref > 0)

        {

            var start = retref + 9;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

    }

}

return result;   (Result is a String of 255 chars len)

This will basically break you response and identifies the actual response values based on some specific tags. In the result you will have the response actual values you are looking for to fill back in actual specific fields of the BO you r designing.

This should work out. Basically above parsing is a example one may not be useful completely, but you have build your own parser function according to the need and your response style.

Thanks.

Regards

Hanu

former_member187060
Participant
0 Kudos

Hi Hanumath,

Thanks for your reply i will try parsing the string.

Can you please let me know how can i pass the multiples input entries in the Body like i have multiple leads in C4C which i need to update it to the Marketo.

I cant pass it one by one not best practice so how can i pass multiple inputs entries in one request.

request body should be like below.

I have used below format for single entry.

Body = "{ \"action\" : \"createOrUpdate\" , \"lookupField\" : \"email\" , \"input\":[ { \"email\": \""+ email1 +"\" , \"firstName\": \""+ name +"\" , \"postalCode\": \"" + postal +"\" } ] } ";

var ws_result = WebServiceUtilities.ExecuteRESTService(ScenarioName, ServiceName, HttpMethod, HttpResource , URLParam , HeaderParameter ,ContentType , Body );

Kindly help me in this issue.

Thanks,

Siraj.

Former Member
0 Kudos

Hi Siraj,

API you are trying to consume should be having some syntax with it to pass the multiple entries in the body with some special characters.

I am not sure whether your API supports multiple entries to pass in the Body request or not? Please check it with your API provider.

If any real time syntax of the API is available for passing the multiple values, I hope I can help you in that.

Thanks.

Regards

Hanu

former_member187060
Participant
0 Kudos

Hi Hanu,

I have checked from my third party end and found that they are using the below format for multiple entries in the request body in the input .

Like one body request contains multiple entries or records to be created or updated at the third party.

Like below should be our body request from ABSL with multiple entries in the input.

So is there a way that we can pass the multiple entries in one body request from ABSL like i have shown in my previous post that i have used the single entry for request in the body so like that can we pass the multiple entries ?


Kindly help.


Regards,

Siraj.

Former Member
0 Kudos

Hi Siraj,

Yes as expected the special character which will separate out each entry is comma(,) in the above request syntax.

So please try to build your Body in the above JSON format with the help of (,) for separating multiple entries.I see in previous threads you already had a code structure to build the body in JSON format. Please use it.

Hope this should work for your and obtained response can be parsed as mentioned in my first thread.

Thanks.

Regards

Hanu.