paypal REST api: shipping_address does not understand utf8 characters - node.js

I'm requesting out of a node application via the nodejs sdk:
paypal.payment.create({ ... }, function (err, transaction) {
fn(err, transaction);
});
The shipping_address payload looks like this:
{
recipient_name : 'Max Mustermann',
line1 : 'Neue Schönhauser Str 18', // the 'ö' causes error
line2 : 'Vorderhaus, links',
city : 'Berlin',
country_code : 'DE',
postal_code : '10178',
state : 'BE',
type : 'residential'
}
The utf-8 character in line1 key's value causes a MALFORMED_REQUEST error. If I replace it by oe everything works fine.
Does paypal's REST api understand utf-8?
Do I have to setup the character encoding somewhere?
Thx

Issue was due to incorrect Content-Length getting set from the nodejs sdk and not the API. We have fixed the SDK and published the latest version to npm. Please use 0.6.4 version which has the fix for the same. Thanks for reporting.

It should accept this, yes, of course. Let me check this for you as it shouldn't throw an error on that.

Related

Complex Queries for Side-by-Side SuccessFactors extension using SAP Cloud SDK (NodeJS)

I am trying to create request builders using SAP Cloud SDK for calling Successfactors Odata APIs. I am facing issues with complex OData querying that includes $expand and maybe custom fields.
https://xxxx.xxxx.xx/odata/v2/WfRequest(11111L)?$expand=wfRequestUINav
I created the request builder as below for the above api:
WfRequest.requestBuilder()
.getByKey(11111)
.select(
WfRequest.WF_REQUEST_UI_NAV
)
.execute({
destinationName: "sfapi"
});
I am getting the below error:
OData get by key request failed!
So I modified the code by adding TO_ to WF_REQUEST_UI_NAV as below:
WfRequest.TO_WF_REQUEST_UI_NAV
but still getting the same error. So I thought it may be a custom field and changed the code as below:
const WF_REQUEST_UI_NAV = WfRequest.customField('wfRequestUINav');
function getWFRequestsDetail() {
return WfRequest
.requestBuilder()
.getByKey(11111)
.select(
WF_REQUEST_UI_NAV
)
.execute({
destinationName: "sfapi"
});
I got the below output, but not the expanded result:
{
"wfRequestUINav": {
"__deferred": {
"uri": "https://api12preview.sapsf.eu/odata/v2/WfRequest(11111L)/wfRequestUINav"
}
}
}
Can anyone help in fixing this issue?
Thanks & Regards,
Harish
I guess the answer can be found in the answers.sap.com as mentioned.

Query params from service A parsed into unexpected object structure in service B and unsure why it is happening

Problem: Encountered a really weird bug when our service A (laravel php) calls an endpoint by service B (nodejs typescript + ajv + nestjs).
Let me explain it further below.
Example code in service A for building the query parameters
$ids = [1,2,3];
$queryParams = http_build_query(['ids' => $ids]);
dump($queryParams)
// ids%5B0%5D=1&ids%5B1%5D=2&ids%5B2%5D=3
// b.com/bar?ids[0]=1&ids[1]=2&ids[2]=3
In service B, the expected received query params should be
{ ids: [1,2,3] }
It worked all well in dev, code deployed to production, then we started seeing validation errors from SOME of the requests because the query params is now
{
ids: {
'0' : '1',
'1' : '2',
'2' : '3'
}
}
We are pretty sure latest code is deployed to all instances so that rules out possibility of code difference in service A causing the difference in query params sent.
Spent 1 whole day trying to trace the root cause but still no answers at the moment.
Question: What format could the query parameters be sent in in order for it to be parsed into the object structure above?
Turns out the issue is due to nestjs #Query decorator (which uses Express under the hood) being unable to parse the query params correctly into expected array if length of params is above 21.
e.g
Query array with 21 elements
ids[0]=160431133&ids[1]=16048883&ids[2]=16048882&ids[3]=16041333&ids[4]=16041313&ids[5]=16041303&ids[6]=16041293&ids[7]=16041283&ids[8]=16041273&ids[9]=16041263&ids[10]=16041253&ids[11]=16041243&ids[12]=16041233&ids[13]=16041133&ids[14]=19116791&ids[15]=19116691&ids[16]=19116591&ids[17]=19116590&ids[18]=19116581&ids[19]=19116571&ids[20]=12416591&
Parsed as
['160431133', ...., '12416591']
Query array with more than 21 elements
ids[0]=160431133&ids[1]=16048883&ids[2]=16048882&ids[3]=16041333&ids[4]=16041313&ids[5]=16041303&ids[6]=16041293&ids[7]=16041283&ids[8]=16041273&ids[9]=16041263&ids[10]=16041253&ids[11]=16041243&ids[12]=16041233&ids[13]=16041133&ids[14]=19116791&ids[15]=19116691&ids[16]=19116591&ids[17]=19116590&ids[18]=19116581&ids[19]=19116571&ids[20]=12416591&ids[21]=123456789
Parsed as
{
'0': 160431133
.
.
.
'21': 123456789
}

Parse values from the JSON returned by URL of Google Place API

I am creating a bot using dialogflow-fulfillment, and I am using Google Place API to pull additional information about hospitals.
I have made a dummy response, for the sake of example, that is returned by Google Place API, here is the link: http://www.mocky.io/v2/5c2b9f9e3000007000abafe3
{
"candidates" : [
{
"formatted_address" : "140 George St, The Rocks NSW 2000, Australia",
"name" : "Museum of Contemporary Art Australia",
"photos" : [
{
"height" : 3492,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/105784220914426417603/photos\"\u003eKeith Chung\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAaGaCX-kivNEaJ-z97AduTYgW3d98uv53-8skNrS1k1GTgOtiQ1-Z2gfWJydrpkrshuV_kHPKizl088dezEJgIxYGoTWqtJgah-u_I46qNNYMfUbk8LKBZqxzkHyIL1nWEhBO6lPa0NgvlyLGBrXpXFPUGhT0lAUj_oCiOWV2MEYdBeKf-kTtgg",
"width" : 4656
}
]
}
],
"status" : "OK"
}
I need to parse values of my choice from the JSON returned by Google Place API. For example, If I had to parse value of 'name' from the JSON above using Python, I would do this:
import requests, json
api_key = ''
r = requests.get('https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Museum%20of%20Contemporary%20Art%20Australia&inputtype=textquery&fields=photos,formatted_address,name&key=' + api_key)
x = r.json()
y = x['candidates']
print(y[0]['name'])
Above code for the job is lucid and works perfectly. Considering my inexperience in Nodejs, would you please let me know something similar in Nodejs to parse the value, for instance, the value of 'name'?
Your valuable reply will encourage me.
P.S: Humbly, the question involves first making a call to Google Place API and then parsing values from the returned JSON. Please follow the steps given in Python code above for better understanding.
Get the API response in an async HTTP request (there are tons of npm libraries like request to help you automatically set headers etc), then use standard library JSON.parse(body) to get an plain JavaScript object which contains a structured representation of the API response.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

How to use Pinpoint to send a text message from a long code in python?

I am currently using boto3 to send text messages to my audience. The problem is that the text message always comes from a short code regardless of whether I put one of my valid long codes in the OriginationNumber field.
client.send_messages(
ApplicationId='appID',
MessageRequest={
'Context': {},
'Addresses': {
event['phone_number']: {
"ChannelType": "SMS"
}
},
'MessageConfiguration': {
'SMSMessage': {
'Body': 'hello world',
'OriginationNumber': "+15405551234",
'MessageType': 'TRANSACTIONAL'
}
}
}
)
If anyone else runs into this. I have to open a support ticket with aws and provide them with a use case describing my application. So, sign-in into the console and head to the support section.

How to extract the message value from JSON in Node.js

My JSON is:
body =
{
"session_id":"45470003-6b84-4a2b-bf35-e850d1e2df8b",
"message":"Thanks for calling service desk, may I know the store number you are calling from?",
"callstatus":"InProgress",
"intent":"",
"responseStatusCode":null,
"responseStatusMsg":null,
"context":"getstorenumber"
}
How to get message value using Node js? Please let me know after testing.
i tried body.message and body['message'] and also body[0]['message']. I am always getting "undefined"
#Chris comment, since the problem is sorted out, Adding the answer to all members for future ref.
From node.js result, body is taken as JSON string, using JSON.parse.body converted to json object.
body =
{
"session_id":"45470003-6b84-4a2b-bf35-e850d1e2df8b",
"message":"Thanks for calling service desk, may I know the store number you are calling from?",
"callstatus":"InProgress",
"intent":"",
"responseStatusCode":null,
"responseStatusMsg":null,
"context":"getstorenumber"
}
JSON.parse.body
console.log(body.message);

Resources