Library
SalesSearch Examples
Listing Sales using MFC and C++
List all currently parked sales, which is phase=5, created after 1-Jan-2020
// Create the request URL
char* MyRmSystem = "1_2_3_4";
char targetUrl[1000];
sprintf_s(targetUrl, "/OpenApi2_%s/SalesSearch?querytext=phase(5)&after=1-Jan-2020", MyRmSystem);
// Prepare a connection
CInternetSession sess;
CHttpConnection* pHttp = sess.GetHttpConnection("fieldpine.com", 0, (short)443);
const char* Accept[2] = { "application/json", NULL };
DWORD SessFlags = INTERNET_FLAG_SECURE;
CHttpFile* pRf = pHttp->OpenRequest("GET", targetUrl, NULL, 1, (const char**)Accept, NULL, SessFlags);
pRf->AddRequestHeaders("X-Api-Key: YOUR-KEY-GOES-HERE\r\n", HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
pRf->SendRequest(NULL, 0, NULL, 0);
DWORD Status = 0;
pRf->QueryInfoStatusCode(Status);
// Read Content regardless of status
CString ct;
pRf->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, ct);
long ContentLength = atol(ct);
CString ReplyString;
if (ContentLength > 0) {
unsigned char bb[8192*4];
int rl = pRf->Read(bb, sizeof(bb));
while (rl > 0) {
ContentLength -= rl;
ReplyString += CString(bb, rl);
if (ContentLength > 0) {
rl = pRf->Read(bb, sizeof(bb));
} else rl = 0;
}
}
if ((Status >= 200) && (Status <= 299)) {
// Process ReplyString here - it contains the server response
}
// Cleanup...