Axios - Sending a GET with & sign - axios

I have a GET call (/getTag) that has a variable 'name'.
One of my users created on with a & sign. And unfortunately the GET call is now failing because it looks like this.
/getTag?name=IS&me-1234
Unfortunately my server interprets it like this because of the & sign:
{ id: 'IS', 'me-1234': '' }
Anyone experienced this before and have a way to solve it?

You should use encodeURIComponent on a variable name before passing it to axios.

You can use params key in axios
axios.get('/getTag', {params: {name: 'Is&me123'}})

You should request like:
axios.get('https://your-site.com/getTag', { params: { name: 'IS&me-1234' } });
instead of:
axios.get('https://your-site.com/getTag?name=IS&me-1234');

Related

sendgrid substitutions not working

I'm just trying to set up a trial email for SendGrid, it's the first time I've used it so I'm sure this is simple, but I can't seem to get the placeholder data to replace.
I'm using NodeJS library like this:
sgMail.setApiKey(mailConfig.apiKey);
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
substitutions: {
'--displayName--': original.displayName,
'--companyName--': 'Hello world'
}
};
console.log('Sending: ', msgConfig);
// now send the registration confirmation email.
return sgMail.send(msgConfig).then(() => {
console.log('done.');
})
.catch((err) => {
console.error(JSON.stringify(err));
});
And in the template there's a text block that I added using the visual editor:
Hello --displayName--
We would love to take this opportunity to welcome you to the store.
from
--companyName--
However when I run the test to send the email, it sends the mail okay, but doesn't substitute the placeholders.
What am I missing here?
try changing 'substitutions' to 'dynamicTemplateData'. Looks like they changed the name in the new version.
how i figured it out:
https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/USE_CASES.md
It is not clear in Sendgrid documentation, but I think it is missing this line:
sgMail.setSubstitutionWrappers('--', '--'); // Configure the substitution tag wrappers globally
Then remove dashes in substitutions object keys
Look at this link: Sendgrid
So, your code should be:
sgMail.setApiKey(mailConfig.apiKey);
// Configure the substitution tag wrappers globally
sgMail.setSubstitutionWrappers('--', '--');
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
substitutions: {
'displayName': original.displayName,
'companyName': 'Hello world'
}
};
...
I hope this helps you!
For anyone NOT using dynamic templates, use Sendgrid's helpers as described here: substitution use case
IMPORTANT: If using personalization helper, don't forget to set your setSubstitutionWrappers at the PERSONALIZATION level like so personalization.setSubstitutionWrappers(['%%', '%%']).
If not using personalization, just set it at the global helper:
import mailClient from '#sendgrid/mail';
mailClient.setSubstitutionWrappers('%%', '%%')
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
};
msgConfig.addSubstitution('%displayName%', 'Something to display');
It seems user given variables don’t work when you have the angle brackets <% ... %> around them, these are reserved for the <%body%> and <%subject%> tags.
So now you can make your template that might look something like this - %displayName%

LOOPBACK REST API for 'LIKE'

how can i type the REST API for "LIKE" Query on LoopBack ?
according to Loopback Documentation,
i already try like this :
ProductDealers?filter={"where":{"DealerCode":"T001","Active":"true","SKU":{"like":"1000.*"}}}
but it nothing happens,
please help me?
It would be something like
Post.find({
where: {
title: {
like: 'someth.*',
options: 'i'
}
}
});
and for api calls
?filter={"where":{"title":{"like":"someth.*","options":"i"}}}
Please take a look at this PR for more info
i found the answer , i didn't know why its can't work when i used brackets " {} "
but when i used " [] " , it works very well, like
Products?filter[where][Name][like]=%25" + valFilter + "%25&filter[where][Active]=1&filter[where][Deleted]=0"
Cheers!
A bit late but i actually found this after looking for something else.
The problem for most people is, that there is something called Url Encoding.
Read more here:
https://en.wikipedia.org/wiki/Percent-encoding
So if you stringify your json filter like in the examples above, make sure you put the stringified object into an Uri Encoder which will make sure you will get what you expect and will control the encoding of your values
let t_filter = {
where: {
title: {
like: 'someth.*',
options: 'i'
}
}
};
let result = encodeURI(JSON.stringify(t_filter));
After that send the result to your Api and not only the stringified Object

How to read query parameters in spray?

I want to get parameters such as String and integer in spray,for example:
http://localhost:8080/nexus?taskId=1&operatorId=3&version=10&day=12&hour=7&minute=3
I use code:
path("nexus"){
get {
parameters('taskId.as[Int], 'operatorId.as[Int],'version.as[Int],'day.as[Int],'hour.as[Int] ,'minute.as[Int])
{ (taskId,operatorId,version,day,hour,minute) =>
complete{s"$taskId"}
}
}
I use this code to test:
curl http://localhost:8080/nexus?taskId=1&operatorId=3&version=10&day=12&hour=7&minute=3
But it's lead to this error:
Request is missing required query parameter 'operatorId'
and operatorId really exist!
I don't know How to do!
The code is correct. Just wrap the URL with double quotes:
curl "http://localhost:8080/nexus?taskId=1&operatorId=3&version=10&day=12&hour=7&minute=3"

Error while issuing REST put request to Google Firebase [duplicate]

I'm trying to make a POST request from Parse to Firebase, using Parse Cloud Code and Firebase's REST API.
Parse.Cloud.define("createChatRoom", function(request, response) {
Parse.Cloud.httpRequest({
url: 'https://myapp.firebaseIO.com/' + '.json',
method: 'PUT',
body: {"hi": "hello"}
}).then(function(httpResponse) {
response.success("Successfully posted hello!");
},function(httpResponse) {
response.error("failed to post hello" + httpResponse.text)
})
})
However, this code makes Firebase respond with the following error:
"Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."
I have tried a multitude of combinations for body, including variations of apostrophes, integers, and removing brackets altogether.
Any ideas?
Answering my question:
JSON for Firebase must be wrapped in single quotes ':
body: '{"hi": "hello"}'
I think it's better to use like this body: JSON.stringify({"hi": "hello"})

Sencha Touch: How to build a restful proxy url syntax?

Defined as a model and its associations, I wish the http calls to follow best practices of restful. For example, if I make the call
user.posts();
I wish to run a call http defined as
users/1/posts
If a call is then put on post with id 32 then the url of reference must be
users/1/posts/32
So I want to avoid using the filter property as is the default for a get
/posts.php?filter=[{"property":"user_id","value":1}]
This is because the api rest are already defined and I can not change them.
I would like to build a minimally invasive solution and reading on various forums the best way is to do an ovveride the method buildURL the proxy rest but was not able to retrieve all the data needed to build the final URL. Can anyone give me an example?
thanks
Try the following:
window.serverUrl = "192.168.1.XX"
var service = "login.php"
var dataTosend: {
username:"xx",
password: "yy"
}
var methode:"POST" / "GET"
this.service(service,methode,dataTosend,onSucessFunction,onFailureFunction);
onSucessFunction: function(res) {
alert("onSucessFunction"):
},
onFailureFunction: function(res) {
alert("onFailureFunction"):
},
service: function(svc, callingMethod, data, successFunc, failureFunc) {
Ext.Ajax.request({
scope: this,
useDefaultXhrHeader: false,
method: callingMethod,
url: window.serverUrl + svc,
params: data,
reader: {
type: 'json'
},
failure: failureFunc,
success: successFunc
});
I hope this will solve your problem...