question

office-after-office13172 avatar image
office-after-office13172 asked ·

want to send SMS using Microsoft SQL Server's store Procedure

we want to send SMS using Microsoft SQL Server's store Procedure, plz. guide me if there is any sample code available ?
topic-default
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered ·
Hi,

I am not sure how do you exactly want to send SMS with MS SQL store procedure, which is a database environment. Can you explain more details how and what you want to achieve?

Meanwhile, check this tutorial to learn how you could implement an A2P SMS application. 

Hope this helps,

+ Phong
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

office-after-office13172 avatar image
office-after-office13172 answered ·
Hi, thx for your reply, we are using Microsoft SQL server database, where we have a table with all the phone numbers to send SMS, (each SMS is unique to that number),

we want to build a DB job to automate this, below is the sample code which we are going to using ,

it will be helpful if you provide us all the steps (e.g. API to login and get the token so that token we will use in SMS API )
 
--- below is the sql sample code, this is working fine if I login manually and collect the token from browser trace/debugger 

Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
DECLARE @reqHead AS VARCHAR(8000) = 
'{"Authorization": "U0pDMTFQMDFQQVMwMHxBQUF3NlMxZlNtZ1NCZEF5NTJrd1BnOFZkOWhhdlVnZkdGamVTeVpTTGxWdjhscmY4ZHN0NjlvQm1Lc0poVkZZbXNsNF9QWWRPMEVYNEV2UTBjM2U1NkM0MFk0SDhFeUVhUkhIczcycTVONm13MjNxcV9xVFkxUHA1cXZjWmZLMXEzcDBXaWdqNm4zdllvLUUyT1ZCSHExZmRvRFJIWVlnYXBKR1htc2JrZ0dWemVmQTRfLXU3WEUtSngwbTRLNzhIeDRKVVN6ZkR6NnRpUjIybjZmLU12cmN8VjVqczBRfFVEdzVrQ3BLbFduOTZFbzZ6c1d6QkF8QUE"}'

DECLARE @Body AS VARCHAR(8000) = 
'{
    "from": {"phoneNumber": "+17xxxxxxxx1"},
    "to": [{"phoneNumber": "+152xxxxxxxx4"}],
    "text": "Hello, Jack"
}'  
-- Code Snippet  MSXML2.ServerXMLHttp     MSXML2.XMLHTTP
Exec sp_OACreate 'MSXML2.ServerXMLHttp', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'post',' https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms ', 'false'
EXEC sp_OAMethod @Object, 'setRequestHeader', @reqHead, 'Content-Type', 'application/json'
Exec sp_OAMethod @Object, 'send', null, @body
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Select @ResponseText

Exec sp_OADestroy @Object



3 comments Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks for clarification!

Well, I am not an expert in MS SQL Server language. But since you could post a request to send SMS using a hardcoded token. I think it would be easy for you to try with the request for access token as well. Just make your app a Server Only app so you can use the password flow authentication to get the access token.

Alternatively, if you think about using Node JS to access your MS SQL Server db, then I can help with the code in Node JS to login and send SMS.

Let me know,

+ Phong
0 Likes 0 · ·
I have develop a MS-SQL Server Stored Procedure to send the SMS, let me know if it will be helpful if I post the sample code here.

0 Likes 0 · ·
Congrats for making it work!

Thanks a lot for your great intention to share the code. Surely you can post your code here within the pre<> code block. But if you have a Github account, you can make a repo there and share the link here. We can promote it and star your repo and that would make you a greater contributor to our dev community.

Bests,
+ Phong
0 Likes 0 · ·
JEEVI ANU avatar image
JEEVI ANU answered ·
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

JEEVI ANU avatar image
JEEVI ANU answered ·
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Khadhar Koneti avatar image
Khadhar Koneti answered ·

Hi Jeevi,

Why are you posting this types of links in this forum.

Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.