I am trying to call netsuite API in laravel using guzzle But it showing Unauthorized 401 status code. It is working in Curl. I am setting header according to documentation
Pasted Error here which is showing
{"type":"https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.2","title":"Unauthorized","status":401,"o:errorDetails":[{"detail":"Invalid login attempt. For more details, see the Login Audit Trail in the NetSuite UI at Setup > Users/Roles > User Management > View Login Audit Trail.","o:errorCode":"INVALID_LOGIN"}]}
Here is my code I am using
public function TestNsAPI`enter code here`()
{
$client = new Client(['verify' => false]);
$url = $baseurl."/services/rest/record/v1/inventoryItem";
$method = "GET";
$nonce = md5(mt_rand());
$timestamp = time();
$signatureMethod = 'HMAC-SHA256';
$version = "1.0";
$baseString = restletBaseString($method, $url,config('netsuite.customerKey'),
config('netsuite.accessToken'), $nonce, $timestamp, $version, $signatureMethod,null);
$key = rawurlencode(config('netsuite.customerSecret')) .'&'. rawurlencode(config('netsuite.tokenSecret'));
$signature = base64_encode(hash_hmac('sha256', $baseString, $key, true));
$header = 'OAuth '
.'realm="' . rawurlencode(config('netsuite.netsuiteAccount')) .'", '
.'oauth_consumer_key="' . rawurlencode(config('netsuite.customerKey')) .'", '
.'oauth_token="' . rawurlencode(config('netsuite.accessToken')) .'", '
.'oauth_nonce="' . rawurlencode($nonce) .'", '
.'oauth_timestamp="' . rawurlencode($timestamp) .'", '
.'oauth_signature_method="' . rawurlencode($signatureMethod) .'", '
.'oauth_version="' . rawurlencode($version) .'", '
.'oauth_signature="' . rawurlencode($signature) .'"';
$response = $client->get($url,['headers' => ['Content-Type' => 'application/json','Authorization' => $header] ]);
$data = json_decode($response->getBody()->getContents(), true);
dd($data);
}