Hi,
I'm attempting to use suiteql but am always getting a 401 INVALID_LOGIN response. I'm using exactly the same php code to generate the tokens etc that works successfully with GET calls to endpoints beneath /services/rest/record/v1 but does not work with POST calls to /services/rest/query/v1/suiteql
My code looks like this:-
$fullUrl = "$NS_API_BASE_URL/services/rest/query/v1/suiteql";
$httpMethod = 'PUT';
$signatureMethod = 'HMAC-SHA256';
$nonce = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
$timestamp = time();
$version = '1.0';
$query = [
"q" => "select * from customer"
];
$baseString = oauth_get_sbs($httpMethod, $fullUrl, array(
'oauth_consumer_key' => $NS_CLIENT_ID,
'oauth_nonce' => $nonce,
'oauth_signature_method' => $signatureMethod,
'oauth_timestamp' => $timestamp,
'oauth_token' => $NS_TOKEN_ID,
'oauth_version' => $version));
$signatureKey = rawurlencode($NS_CLIENT_SECRET) .'&'. rawurlencode($NS_TOKEN_SECRET);
$signature = base64_encode(hash_hmac('sha256', $baseString, $signatureKey, true));
$curl_opts = array(
CURLOPT_URL => $fullUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array(
'Authorization: OAuth realm="' . rawurlencode($NS_ACCOUNT_ID) . '",
oauth_consumer_key="' . rawurlencode($NS_CLIENT_ID) . '",
oauth_token="' . rawurlencode($NS_TOKEN_ID) . '",
oauth_signature_method="HMAC-SHA256",
oauth_timestamp="' . $timestamp . '",
oauth_nonce="' . rawurlencode($nonce) . '",
oauth_version="1.0",
oauth_signature="' . rawurlencode($signature) . '"',
'Content-Type: text/plain',
'Cookie: NS_ROUTING_VERSION=LAGGING',
'Prefer: transient'
),
CURLOPT_POSTFIELDS => json_encode($query),
);