Parsing application/json when Exposing REST Web Service

Parsing application/json when Exposing REST Web Service

  

Hi There,


In Service Studio 9.1, I am working on exposing a REST Web Service that is supposed to receive application/json data. I created the structure that will map to the JSON object and I have set the data type of input variable to that structure and set the Receive in to "Body", but the no field gets mapped. I have attached the sample OML of the way I have set things up. Can someone please check what am I doing wrong here? 

To use a sample JSON object to test, please use the one below:

{
   "created":1326853478,
   "livemode":false,
   "id":"evt_00000000000000",
   "type":"charge.succeeded",
   "object":"event",
   "request":null,
   "pending_webhooks":1,
   "api_version":"2016-07-06",
   "data":{
      "object":{
         "id":"ch_00000000000000",
         "object":"charge",
         "amount":901,
         "amount_refunded":0,
         "application_fee":null,
         "balance_transaction":"txn_00000000000000",
         "captured":true,
         "created":1476993920,
         "currency":"cad",
         "customer":"cus_00000000000000",
         "description":null,
         "destination":null,
         "dispute":null,
         "failure_code":null,
         "failure_message":null,
         "fraud_details":{

         },
         "invoice":null,
         "livemode":false,
         "metadata":{

         },
         "order":null,
         "outcome":{
            "network_status":"approved_by_network",
            "reason":null,
            "risk_level":"normal",
            "seller_message":"Payment complete.",
            "type":"authorized"
         },
         "paid":true,
         "receipt_email":null,
         "receipt_number":null,
         "refunded":false,
         "refunds":{
            "object":"list",
            "data":[

            ],
            "has_more":false,
            "total_count":0,
            "url":"/v1/charges"
         },
         "review":null,
         "shipping":null,
         "source":{
            "id":"card_00000000000000",
            "object":"card",
            "address_city":null,
            "address_country":null,
            "address_line1":null,
            "address_line1_check":null,
            "address_line2":null,
            "address_state":null,
            "address_zip":null,
            "address_zip_check":null,
            "brand":"Visa",
            "country":"US",
            "customer":"cus_00000000000000",
            "cvc_check":null,
            "dynamic_last4":null,
            "exp_month":12,
            "exp_year":2019,
            "funding":"debit",
            "last4":"5556",
            "metadata":{

            },
            "name":"a@b.c",
            "tokenization_method":null
         },
         "source_transfer":null,
         "statement_descriptor":null,
         "status":"succeeded"
      }
   }
}



Solution

Hi Gurvinder,


I'm pretty sure the issue the the "case" of your attributes ("Created" instead of "created")

Since you are still in P9.1 there is no way to configure a different name of the attribute than the one in the JSON.
In version 10 there is a new property on attributes called "Name In JSON" that allows it


So if you need the names on the JSON to be in lowercase you will need to change all your attributes to match that casing.

(It was smart to copy paste the structures from a Consume REST API ..but in 9.1 they lose the "Original Name" property during the copy paste operation since they do not have that capacity yet) 



Edit: by the way, you should try to get a more complete example of the JSON, without the "null" and empty arrays. You are missing some attributes on the structures because of that.


Edit 2: Not related, but not sure why you are changing the status code to 200, that is already the default.


Regards,
João Rosado

Solution

Hi João,

Thanks, got it working by changing the case of attributes. I didn't notice while copying structure from consuming web service that they had 'Original Name' property there and kept scratching wondering about it. 

I will make changes in the structure for getting the null ones as well, this one was for testing only and;

I was testing 'SetStatusCode' action to see how it works, that's why it is there.


Thanks,
Gurvinder

Good to know that you got it working  :)