-1

I want to use finerworks api and my curl code is here

$data1 = array(
'web_api_key' => '********-****-****-*****-************',
'app_key' => '********-****-****-*****-************',
);
$data2['credentials'] = $data1;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data2),
CURLOPT_HTTPHEADER => array(
    "accept: */*",
    "accept-language: en-US,en;q=0.8",
    "content-type: application/json",
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r(json_decode($response));
}

when i run this code here is my request response below

stdClass Object ( [Message] => The request is invalid. [ModelState] => stdClass Object ( [ApiC.Models.authorization_credentials] => Array ( [0] => Missing or unauthorized api credentials ) ) ) 

Please help me to solve this thanks in advance

1 Answer 1

2

Pass the credentials in header

$data1 = array(
    'web_api_key' => '********-****-****-*****-************',
    'app_key' => '********-****-****-*****-************',
);
$data2['credentials'] = $data1;
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($data2),
    CURLOPT_HTTPHEADER => array(
        "accept: */*",
        "accept-language: en-US,en;q=0.8",
        "content-type: application/json",
        "web_api_key: YOUR web_api_key",
        "app_key: YOUR app_key",
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:".$err;
} else {
    print_r(json_decode($response));
}
Sign up to request clarification or add additional context in comments.

1 Comment

I have set this and now it is showing this error stdClass Object ( [Message] => An error has occurred. [ExceptionMessage] => Object reference not set to an instance of an object. [ExceptionType] => System.NullReferenceException [StackTrace] => at System.Object.GetType() at ApiC.Models.CustomValidator.RequiredOrderList.IsValid(Object value, ValidationContext validationContext) in D:\Visual Studio 2017\Projects\ApiC\ApiC\Models\CustomValidator.cs:line 233

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.