Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Authorization Basic

Status
Not open for further replies.

FoxAll

Programmer
Jun 13, 2003
49
CA
Hi,

I use OneSignal.com for notification.
I read the instruction on how to send a notification, I try it with node.js
Worked on my first try with the oneSignal exemple for node.js.

Now, I try to convert in vfp9 to have the capability to send notification directly from my VFP application.
But, I always get the same error result whatever what I try.

Here is the error :
{"errors":["Please include a case-sensitive header of Authorization: Basic \u003cYOUR-REST-API-KEY-HERE\u003e with a valid REST API key."],"reference":["]}


Here is the vfp code I have so far
Can someone help me?



Code:
CLEAR 

loXMLHTTP = CREATEOBJECT("MSXML2.XMLHTTP")

cUrl="[URL unfurl="true"]https://onesignal.com/api/v1/notifications"[/URL]
loXMLHTTP.OPEN("POST", cUrl ,.F.)

loXMLHTTP.setRequestHeader("Content-Type", "application/json; charset=utf-8")

myheader = STRCONV("ATcyNDU1MmEtMDA5Yi00ZDNmLTkxNzMtNTc4MTUzOGY2ZjE5", 13)
loXMLHTTP.setRequestHeader("Authorization", "Basic " + myheader + "")

cmessage =  '{"app_id": "16eb9e36-19a5-X431-a10f-bb6968058215",' + ; 
			 '"contents": {"en": "English Message"},' + ;
			 '"included_segments": ["All"]}'

cmessage = CREATEBINARY(cMessage)

loXMLHTTP.send(cMessage)

?loXMLHTTP.responseText

RETURN


Thanks for you help.
Bob
 
First off:

dontsharet_nadouy.jpg


So reset your API key, if you haven't already.

You're not following the hint in the error message.
1. You're asked to give your key, not the decoding of it
2. You're asked to put it into \u004c, which simply are double quotes.

The way you have your header string in double quotes you don't get double quotes in the header string.
So use the alternative single quotes or square brackets as string delimiters for assigning the header variable:

Code:
myheader = 'Basic "' + yourAPIkey + '"'
loXMLHTTP.setRequestHeader("Authorization", myheader)

Bye, Olaf.

Olaf Doschke Software Engineering
 
Actually \u003c and \u003e are not double quotes. Double quotes are CHR(34), something with thirty, but decoimal, not hexadecimal.

Anyway, I'm not even sure the error message means to include these delimiters, they may just be markers for a placeholder. You have your node.js reference and could simply compare what you send with node.js vs VFP using fiddler and then adapt your VFP code.

Bye. Olaf.

Olaf Doschke Software Engineering
 
This is fake key numbers.

But I get my notification message now! :)
I googled this before my post:
Code:
It's a unicode character. In this case \u003C and \u003E mean :
U+003C < Less-than sign
U+003E > Greater-than sign

so I never tryed the '"'

thank you :)
Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top