Twilio HTTP response: Not parsing XML/JSON - json

Using Twilio Studio, my HTTP widget obtains the following JSON from (external) endpoint:
{
"response": {
"say": "1 address found",
"data": [
"10707 Ewing Drive Kansas City Kansas"
]
}
}
However, I am able to access {{widgets.http_address_schedule.body}} but not {{widgets.http_address_schedule.parsed.say}}. Twilio documentation indicates this is possible if my response is JSON.
From documentation at: https://www.twilio.com/docs/studio/user-guide#rest-api
Json: If your function returns valid Json, you should be able to
access it via widgets.MY_WIDGET_NAME.parsed
For example, if you return {"message": "Hi", "person": {"name": "Bob",
"age": 40}}, you can reference that in subsequent widgets as:
widgets.MY_WIDGET_NAME.parsed.message
widgets.MY_WIDGET_NAME.parsed.person.name
widgets.MY_WIDGET_NAME.parsed.person.age
What is the expected way to send data to be parsed by Twilio?

After reviewing Twilio Studio logs, I was able to identify PHP error output embedded in the JSON response. Once the error was resolved Twilio was able to successfully parse response and provide data in parsed key in {{widgets.http_address_schedule.parsed.response.say}}

Related

WSO2 Enterprise Integrater 6.6.0 Response transform XML to Json using XSLT

I got a response from endpoint in WSO2 enterprise Integrator as a XML. I can get it as a Json too. but I need to make suitable response (add more parameters) for my client application. this is the xml response i got from endpoint.
<jsonObject>
<ddd>
<__type>Title</__type>
<AccountNo/>
<AccountExists>1</AccountExists>
<Name>user name</ConsumerName>
<Address> user address</ConsumerAddress>
<TotalDue>1000.38</TotalDue>
<LastBillingCycleAmount/>
<ID>150</ID>
</d>
and also this is the json output i can retrieve from endpoint
{
"ddd": {
"__type": "Title",
"AccountNo": null,
"AccountExists": 1,
"Name": "user name",
"Address": "address",
"TotalDue": "1000.38",
"LastBillingCycleAmount": null,
"ID": 150
}
}
I need transform response like this.
{
"AccountNo": "response_data",
"ConsumerName": "response_data",
"ConsumerAddress": "response_data",
"TotalDue": "response_data",
"additional_para1": "my_data", // parameter that i want to add manually
"additional_para2": "my_data", // parameter that i want to add manually
}
You can use a data mapper mediator [1] to map the input to the desired output. Then use a enrich mediator [2] to enrich the generated payload by adding your own values
[1]-https://ei.docs.wso2.com/en/7.1.0/micro-integrator/references/mediators/data-Mapper-Mediator/
[2]-https://docs.wso2.com/display/EI620/Enrich+Mediator

Is there any documentation for EasyPost that shows the raw JSON for the requests, including headers? Or e.g. a PostMan collection?

I'm just doing the preparation for an integration with EasyPost's Shipping API, which will be server side C#, but we always build a PostMan collection for new integrations, so that we can test data separately from the application if there's an issue.
While I do love the fact that EP provide C# libraries and examples, I'm struggling to find anything that just gives me a list of required headers and the raw JSON format for the body of any requests. It feels a bit like they're just being a little too helpful.
I'll be looking at the Orders endpoint probably.
I've got an account, I've checked all their documentation and searched the internet but haven't found anything so I'm hoping I'm not the first developer to want to use a client application for testing outside my code.
Update:
EasyPost now does have a public workspace https://www.postman.com/easypost-api
with at least 1 public collection
The curl examples are basically the same as json:
For the Address creation example:
-d "address[street1]=417 MONTGOMERY ST"
is the equivalent of
{ "address": { "street1": "417 MONTGOMERY ST" } }
(you might have to escape some characters to be valid json).
Check out How to stimulate cURL request to a request using postman for postman with HTTP Basic Auth.
EasyPost does not provide a public Postman collection; however, here is an example of a shipment Postman body (raw) that could be used. You can adjust the values, actions, objects, etc to your needs.
Using the following, you shouldn't need to pass any headers. You'll pass your API key under the username field with the Basic Auth authorization type.
{
"shipment": {
"to_address": {
"id": "adr_123..."
},
"from_address": {
"id": "adr_123..."
},
"parcel": {
"id": "prcl_123..."
},
"carrier_accounts": {
"id": "ca_123..."
},
"options": {
"address_validation_level": "0"
}
},
"format": "json",
"controller": "shipments",
"action": "create"
}

How do I access a json property nested in the ['error'] property of another json reponse?

I'm requesting a list of possible stock ticker symbols from the Yahoo Stock Lookup API, I used the CORS Anywhere service to avoid problems. Unfortunately the original json response from the Yahoo API gets formatted as 'text' in the CORS anywhere 'error' property.
I used this previously asked question as a reference on how to access nested properties.
this is what the json reponse looks like:
{
"headers": {
"normalizedNames": {},
"lazyUpdate": null
},
"status": 200,
"statusText": "OK",
"url": "https://cors-anywhere.herokuapp.com/http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure during parsing for https://cors-anywhere.herokuapp.com/http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback",
"error": {
"error": {
"line": 9848,
"column": 56,
"sourceURL": "capacitor://localhost/vendor-es2015.js"
},
"text": "YAHOO.Finance.SymbolSuggest.ssCallback({\"ResultSet\":{\"Query\":\"Amd\",\"Result\":[{\"symbol\":\"AMD\",\"name\":\"Advanced Micro Devices, Inc.\",\"exch\":\"NMS\",\"type\":\"S\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Equity\"},{\"symbol\":\"DOX\",\"name\":\"Amdocs Limited\",\"exch\":\"NMS\",\"type\":\"S\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Equity\"},{\"symbol\":\"AMDVX\",\"name\":\"American Century Mid Cap Value Fund R6 Class\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDWX\",\"name\":\"Amana Mutual Funds Trust Developing World Fund Investor\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDAX\",\"name\":\"AMIDEX35 Israel Fund Class A\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDEX\",\"name\":\"AMIDEX35 Israel Mutual Fund\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDCX\",\"name\":\"AMIDEX35 Israel Fund Class C\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDRX\",\"name\":\"American Beacon Mid-Cap Value Fund R6 Class\",\"exch\":\"NAS\",\"type\":\"M\",\"exchDisp\":\"NASDAQ\",\"typeDisp\":\"Fund\"},{\"symbol\":\"AMDLY\",\"name\":\"Amada Holdings Co., Ltd.\",\"exch\":\"PNK\",\"type\":\"S\",\"exchDisp\":\"OTC Markets\",\"typeDisp\":\"Equity\"}]}});"
}
}
This is what I tried:
return this.yahooResult.subscribe(data => {return data['error']['text']['ResultSet']['Result']['symbol']});
I'm trying to access "symbol" : "AMD" from the Yahoo API response that is nested in the "text" property of the CORS repsonse.
I don't get much information from the error:
⚡️ [error] - ERROR
You don't have json there, you have a javascript snippet:
YAHOO.Finance.SymbolSuggest.ssCallback()
With some escaped text passed into it.
It's not a case of parsing this, its a case of fixing the error.
I think you are using the wrong API call. It has a callback parameter in it which is wrapping the reply in a function and breaking cors-anywhere's ability to parse the response.
The url you should be using is:
http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en
Not:
http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=Amd&region=1&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback
Then just plain JSON gets returned and cors-anywhere should be able to parse it.

"status_code": 422, "error_code": "REQUEST_PARAM_PARSE", "detail": "The 'data' parameter must be a list"

I’m using the HTTP Request Wizard to set up a POST request to MonkeyLearn. This endpoint expects a JSON in the request body (or payload body). It must be an object with the data property and a list of the texts you want to classify as value. For example:
{
"data": [
"This is the best sentiment analysis tool ever!!!",
]
}
So, in the HTTP Request Wizard, I set up under Parameters:
Name: data
Value: "This is the best sentiment analysis tool evert!!!"
Type: GetorPost
However, in the preview response I get:
{
"status_code": 422,
"error_code": "REQUEST_PARAM_PARSE",
"detail": "The ‘data’ parameter must be a list"
}
I can’t figure out what list the endpoint expect?
I am not familiar with the "HTTP Request Wizard" and cannot find it either. But from what you've written it is clear that you are sending a string and not an array of strings. You value should look like this: Value: [ "This is the best sentiment analysis tool evert!!!" ]

PUT API with path parameter and request body

I have a PUT API Gateway endpoint which should be used to update a DynamoDB entry.
The id for that DynamoDB entry is given as the path parameter.
I have the following mapping template:
"application/json": {
"id": "$input.params('id')",
"title": "$input.json('$.title')"
}
The id is returned as expected.
If I submit this request body
{
"title": "Hello world"
}
I get the error Could not parse request body into json: Unexpected character (\'t\'
Here's the overview of my AWS management console:
what am I missing?
So I just found the solution:
"title": "$input.json('$.title')"
should be
"title": $input.json('$.title') (without the double quotes).
Source: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference