I have curl
curl -H "Authorization: Bearer token_api_oauth" \
"https://api.smsapi.pl/sms.do?\
from=pole_nadawcy&\
to=48500000000&\
message=treść_wiadomości&\
format=json"
and try in node-red
function
httprequest node
whats wrong?
I have curl
curl -H "Authorization: Bearer token_api_oauth" \
"https://api.smsapi.pl/sms.do?\
from=pole_nadawcy&\
to=48500000000&\
message=treść_wiadomości&\
format=json"
and try in node-red
whats wrong?
You have set the method to POST whereas your CURL will be using GET
The function node is wrong, msg.payload
should be an object with key value pairs matching the URL query arguments.
Or you can set msg.url
and leave it blank in the http-request node. Set the URL of a request : Node-RED
Don't know if this could help...
Translation-of-curl-command-to-http-request
I dont know Polish .. but check this link out ..
apparently your provider has a node.js library that makes sending sms messages more easy
So if you read the Documentation of Node-red of how to install and setup external libraries and use them in a Function node .. the rest is pretty easy according to the example on Github
const smsapi = new SMSAPI('oAuthToken');
const response = async (): Promise<MessageResponse> => {
return await smsapi.sms.sendSms('+48605xxxxxx', 'My first message!');
};
ps. library found by following this link
[EDIT] With the http requests there seems to be better better documenation and examples that i dont see with the node.js library .. so try instead this flow :
[{"id":"b5bdb3e23fbe96ca","type":"function","z":"5847b7aa62131d37","name":"","func":"// curl -H \"Authorization: Bearer token_api_oauth\" \\\n// \"https://api.smsapi.com/sms.do?\\\n// from=sender_name&\\\n// to=44123456789&\\\n// message=message_content&\\\n// format=json\"\n\nlet token_api_oauth = \"token_api_oauth\"\nlet sender_name = \"sender_name\"\nlet to_number = \"44123456789\"\nlet message_content = \"blah blah\"\n\n\nmsg.url = `https://api.smsapi.pl/sms.do?from=${sender_name}&to=${to_number}&message=${message_content}&format=json`\nmsg.method = \"GET\"\nmsg.headers = {\n \"Authorization\" : `Bearer ${token_api_oauth}`\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":920,"wires":[["7369d264e46db45e"]]},{"id":"7369d264e46db45e","type":"http request","z":"5847b7aa62131d37","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":680,"y":920,"wires":[["1afe78da8b5b1790"]]},{"id":"1afe78da8b5b1790","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":920,"wires":[]},{"id":"1be7147b87b23562","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":920,"wires":[["b5bdb3e23fbe96ca"]]}]
the problem was in header content type
msg.headers={
'Authorization': 'Bearer **********************************',
'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
};
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.