Alpaca Authentication with Qt Issue

I’m developing a desktop trading app and am targeting Alpaca first. Specifically, I’m having issues creating the proper HTTP GET header request to do authentication using the Qt framework. Anyone with Qt experience?

Here’s the a few examples I’ve tried and am getting code 40110000.

// 1
QNetworkRequest req(res);
req.setHeader(QNetworkRequest::ContentTypeHeader, “APCA-API-KEY-ID: BLAH”);
req.setHeader(QNetworkRequest::ContentTypeHeader, “APCA-API-SECRET-KEY: BLAHBLAH”);

// 2
QNetworkRequest req(res);
req.setRawHeader("APCA-API-KEY-ID: ", “BLAH”);
req.setRawHeader("APCA-API-SECRET-KEY: ", “BLAHBLAH”);

I’ve looked at This Stack Overflow Post and This Other Stack Overflow Post, but I’m still not getting it.

Thanks for any help!


1 Like

what endpoint url?.. is the endpoint I’m testing with, so I’m using my paper account API key pairs.


I was able to use the curl -H option with my key pairs to successfully authenticate and get a return via terminal. Did that on my mac.

Not very familiar with Qt, but is there any way to dump the raw HTTP request in text for debug purpose?

I’ve been trying that, but it’s not been that helpful since I can’t print out everything like you’d think. I can print out the URL and Raw headers fine and they look like what I set.

One thing I’ve notices is that with cURL, there is no header name specified, but Qt does want you to provide that each time I call setRawHeader().

I got it finally, used the curl -v option to have curl print out all its details which gave me some clues.

Here’s the final solution:

QNetworkRequest req(res);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
req.setRawHeader("APCA-API-KEY-ID",  "BLAH");
req.setRawHeader("APCA-API-SECRET-KEY", "BLAHBLAH");

What actually really did it was removing the colon from the “APCA-API-KEY-ID” parts!