INVALID_REQUEST_ERROR | BAD_REQUEST | DeviceCode must contain a product_type

I’m trying to create a Decive Code, But I get this error.
Square\Models\Error Object ( [category:Square\Models\Error:private] => INVALID_REQUEST_ERROR [code:Square\Models\Error:private] => BAD_REQUEST [detail:Square\Models\Error:private] => DeviceCode must contain a product_type [field:Square\Models\Error:private]

$device_code = new \Square\Models\DeviceCode(‘TERMINAL_API’);
$device_code->setName(‘Counter 1’);
$device_code->setLocationId(‘LRRR39D6WSF8X’);

$body = new \Square\Models\CreateDeviceCodeRequest(‘5bffb735-5ea9-45b4-889a-d33200b12ad3’, $device_code);

$api_response = $client->getDevicesApi()->createDeviceCode($body);

if ($api_response->isSuccess()) {
$result = $api_response->getResult();
$printAr = $api_response->getResult();
print_r($printAr);
} else {
$errors = $api_response->getErrors();
$printAr = $api_response->getErrors();
print_r($printAr);
}

When you called CreateDeviceCode did you include product_type TERMINAL_API? :slightly_smiling_face:

Hi Bryan,
Yes I included like this,
$device_code = new \Square\Models\DeviceCode(‘TERMINAL_API’);

But it give that error.

What’s your application ID? :slightly_smiling_face:

Sanbox Application ID : sandbox-sq0idb-p5g0BM4LLLR_oepB7A_W-g

Production Application ID : sq0idp-PAXILRXRydqPKuyBbFtwkA

18631-ALLVEN-Email-Signature-Generic_V1.png

I took a look at your API Logs and I don’t see product_type included in the request to CreateDeviceCode. You’ll need to add that to have it work as expected. :slightly_smiling_face: