Service Node not working for Post Request

Hi Team,

I am running one API which is written in Python code. Which accept the JSON String and 2 query param. I am not getting Success response from the Platform. However I am able to run the API from Postman.
Following are my observations from BotBuilder side:

  1. Even if I set Content-Type as Application/json, in API side, I am not receiving the JSON body in request.json filed. However, it is getting captured in request.data.
  2. From postman, for the same JSON String, content-length coming as 785, however when I run it from ServiceNode, from BotBuilder content-length coming as 787. There are 2 extra chars in it.
  3. Whenever I do json.loads(request.data.decode(‘utf-8’)) , I do get JSON Decoder error “json.decoder.JSONDecodeError: Extra data: line 1 column 4 (char 3)”
  4. This is the sample code from Postman which I am trying to run from BotBuilder:
    curl --location --request POST ‘http://13.232.71.107:5000/payments?accountID=01FZ7MUV67NDN3P7VLAHA36MBJN4MSW3GPTWPAAA&accessToken=nBVQ3ots9xw48Gz9t3AzdyRHSou4’ \

–data-raw ‘{“Data”:{“Initiation”:{“InstructionIdentification”:“AAA003”,“EndToEndIdentification”:“BBB003”,“LocalInstrument”:“UK.OBIE.CHAPS”,“InstructedAmount”:{“Amount”:“2000.00”,“Currency”:“GBP”},“CreditorAccount”:{“SchemeName”:“UK.OBIE.IBAN”,“Identification”:“222233334445”,“Name”:“Jane Doe”},“CreditorPostalAddress”:{“AddressType”:“Business”,“Department”:“Information Technology”,“SubDepartment”:“Human Resources”,“StreetName”:“Main Street”,“PostCode”:“GU34 1AB”,“TownName”:“Alton”,“CountrySubDivision”:“YYY”,“Country”:“UK”,“AddressLine”:[“999 Test Tower, Main Street”]},“RemittanceInformation”:{“Unstructured”:“CHAPS Remittance”,“Reference”:“REF0003”}},“Authorisation”:{“AuthorisationType”:“Single”,“CompletionDateTime”:“2019-12-12T19:42:44.601Z”}},“Risk”:{“PaymentContextCode”:“BillPayment”}}’

By reading at internet on decoding the large json body, I wrote it in file and then read it from file. Still getting same error. However, it is perfectly working from the Postman.

I am struggling with this issue since last week. Kindly help me in this. Kindly let me know if you need more info.

@praful_dhone

I am getting econreset. Is this API accessible from public internet?
I will need the API once to be able to troubleshoot.

curl --location --request POST 'http://13.232.71.107:5000/payments?accountID=01FZ7MUV67NDN3P7VLAHA36MBJN4MSW3GPTWPAAA&accessToken=nBVQ3ots9xw48Gz9t3AzdyRHSou4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Data": {
        "Initiation": {
            "InstructionIdentification": "AAA003",
            "EndToEndIdentification": "BBB003",
            "LocalInstrument": "UK.OBIE.CHAPS",
            "InstructedAmount": {
                "Amount": "2000.00",
                "Currency": "GBP"
            },
            "CreditorAccount": {
                "SchemeName": "UK.OBIE.IBAN",
                "Identification": "222233334445",
                "Name": "Jane Doe"
            },
            "CreditorPostalAddress": {
                "AddressType": "Business",
                "Department": "Information Technology",
                "SubDepartment": "Human Resources",
                "StreetName": "Main Street",
                "PostCode": "GU34 1AB",
                "TownName": "Alton",
                "CountrySubDivision": "YYY",
                "Country": "UK",
                "AddressLine": [
                    "999 Test Tower, Main Street"
                ]
            },
            "RemittanceInformation": {
                "Unstructured": "CHAPS Remittance",
                "Reference": "REF0003"
            }
        },
        "Authorisation": {
            "AuthorisationType": "Single",
            "CompletionDateTime": "2019-12-12T19: 42: 44.601Z"
        }
    },
    "Risk": {
        "PaymentContextCode": "BillPayment"
    }
}'

It is accessible Swagata. I have run the API in background now. It wont stop. You can run the following API with given data previously.

http://13.232.71.107:5000/payments?accountID=01FZ7MUV67NDN3P7VLAHA36MBJN4MSW3GPTWPAAA&accessToken=nBVQ3ots9xw48Gz9t3AzdyRHSou4

Postman Running:

And How I am running on ServiceNode:

@praful_dhone
As mentioned in my earlier post I am unable to access the API. Can you please review the curl I had shared.

Hi Swagata,

The API was accessible to me even on Mobile Network. I am not sure why you were not able to. IP gets changed after every restart of server.

API for today:

http://13.234.120.146:5000/payments?accountID=01FZ7MUV67NDN3P7VLAHA36MBJN4MSW3GPTWPAAA&accessToken=67Mu8MAwsYw4LQeCEoPvNhxTZTXv

Anyway, I got to know how to specify json string data on Kore.
When I removed the double quote from the json string variables, it is started working.:

However, I found sometimes platform appends that double quotes. Here you can see, smsObjStr gets double quoted with platform.

So I thought lets specify the json string in double quotes and the call was failing.
But I still confused, do we need to pass json string with double quotes or without double quotes? Or let platform decide whether it needs to appends with double quotes?

@praful_dhone
I noticed that from the Kore.ai office network/Kore I was unable to access the API but from the open network/mobile I was able to!

from office:

From mobile network:

This looks like an issue with the non-standard port you are using. We block non-standard ports like 5000. So it should explain why this API did not work from the platform/botbuilder. Please use 80 or 443. Better even, hide it behind a domain name or use ngrok for the time being to export the 5000 port.

For double quotes on the {{ }} - My suggestion for you is to remove the double quotes if you use JSON. If you use custom, use double quotes. I can get some more clarity around this.

@swagata.sengupta
Its not like 5000 port is blocking on Kore Bot Builder. It is working perfectly fine for GET method and now for POST method also after removing the double quotes to json body str {{ }}.

One more observation, when you export any Bot from Store then Dialog Tasks looks like Older version of Kore bot platform. Where we need to remove the double quotes and pass the JSON Object by converting into string using JSON.Stringify method. Where as when you create the Dialog Task from scratch on new version of platform, in ServiceNode where we need to specify the JSON Object with JSON.Stringify with double quote.

I think there is different way of calling of APIs in older and newer version of platform. This is my observations :smiley: This might help you to decide where to use double quote and where not.

@praful_dhone
I have some clarifications on the double quote behaviour.
If you use a plain JSON body, like

{
  "key" : "value"
}

no double quote will be added.

If you use something like {{context.abc.body}} in the body, a double quote will be added ONLY in the UI (by the editor interface) as this will be treated as a string. This string does not get passed on to the backend.

Hope this helps.

Hi @praful_dhone
I am also facing the same issue with POST method, can I know the solution.
I have tried removing double quotes, but its automatically getting added again.

Please help us to resolve this. Thank you!

Hi Swagat, Do we have solution for it. It’s still automatically adding double quotes and considering it as string, because of which API is failing.

Thank you in advance!

@truptidudhanikar I think you are using new version of platform, where double quotes get added to the string in UI editor and as confirmed by Swagata, it wont pass to the API. It should work then. First try testing your API in Test Mode by passing hardcoded JSON string. If it works, try testing it by passing it in context variable.

Hi Swagata @swagata.sengupta

I have met same question at version 9.1.

first step, like below code, we add a json on BotUserSession
context.session.BotUserSession.tokenRequest=JSON.stringify({“userToken”:context.session.UserContext.customData.userToken})

second step:
a service node with post method is created, at the body of node, we want get parameter from BotUserSession like below
{{context.session.UserContext.customData.tokenRequest}}

but the bot will always auto adding double quote for it, even I delete it manually. this situation caused our API cant get correct parameter.
“{{context.session.UserContext.customData.tokenRequest}}”

please tell how to deal with this issue, thanks!

@17796837509
I again tried this scenario. I did the below:

  1. Script node sets the variable.
  2. Service node uses it.

    Although the double quotes are added in the UI, this is what my service receives.

Never mind the bad gateway as I am simply trying to simulate what the third party would receive as a part of the POST call. There is no actual service running here.

Maybe you can avoid JSON.stringify.