# Server Error on Requesting Code to Pair Terminal API

**URL:** <https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253>\
**Category:** Questions\
**Tags:** terminal-api\
**Created:** [October 22, 2024, 6:51am UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253 "2024-10-22T06:51:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nHiRanZ](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nHiRanZ](https://developer.squareup.com/forums/u/nHiRanZ)\
**Post date:** [October 22, 2024, 6:51am UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/1 "2024-10-22T06:51:19Z")

</div>

Hi,

When trying to pair the Terminal Payment Device via Terminal API, at the stage of requesting the Pairing Code, one of our merchants seems to be getting an error from Square APIs.

Log:

```auto
2024-10-21 00:19:53 - SQUARE-TERMINAL API >>>>>>>>>> 
URI : https://connect.squareup.com/v2/devices/codes
Method : POST
Headers : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer TOKEN-REDACTED], Square-Version=[2024-01-18], Content-Length=[203]}
Request body: {"idempotency_key":"670f1c710ef632032bbea83b","device_code":{"name":"Sunset Island - Kiosk - A3288SOM0122080211050527 Square Terminal Device","location_id":"LP576VN6Y92PK","product_type":"TERMINAL_API"}}
2024-10-21 00:19:53 - SQUARE-TERMINAL API API <<<<<<<<<< Status = [500] path = [https://connect.squareup.com/v2/devices/codes]
Status code : 500
Status text : Internal Server Error
Headers : {Date=[Mon, 21 Oct 2024 00:19:53 GMT], Content-Type=[application/json], Content-Length=[118], Connection=[keep-alive], CF-Ray=[8d5d14258bc63961-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], frame-options=[DENY], square-version=[2024-01-18], squareup--connect--v2--common--versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/devices/codes/**], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Set-Cookie=[__cf_bm=vC.4NkxDHsVjsfQaMjza1bzL2lBYgvLZRIE.Ry9Rr4k-1729469993-1.0.1.1-xLcHrJ3giiCDbliCn7rEsd3HWyVFI9Y39D5r9r06kNmIIoaISmgZvb_VkbzF_19kCna2i5LldVWr1VvJAuvQcw; path=/; expires=Mon, 21-Oct-24 00:49:53 GMT; domain=.connect.squareup.com; HttpOnly; Secure; SameSite=None], Vary=[Accept-Encoding], Server=[cloudflare]}
Response body: {"errors": [{"code": "INTERNAL_SERVER_ERROR","detail": "An unexpected error has occurred.","category": "API_ERROR"}]}

..

2024-10-21 00:21:30 - SQUARE-TERMINAL API >>>>>>>>>> 
URI : https://connect.squareup.com/v2/devices/codes
Method : POST
Headers : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer TOKEN-REDACTED], Square-Version=[2024-01-18], Content-Length=[203]}
Request body: {"idempotency_key":"670f1c710ef632032bbea83b","device_code":{"name":"Sunset Island - Kiosk - A3288SOM0122080211050527 Square Terminal Device","location_id":"LP576VN6Y92PK","product_type":"TERMINAL_API"}}
2024-10-21 00:21:30 - SQUARE-TERMINAL API API <<<<<<<<<< Status = [500] path = [https://connect.squareup.com/v2/devices/codes]
Status code : 500
Status text : Internal Server Error
Headers : {Date=[Mon, 21 Oct 2024 00:21:30 GMT], Content-Type=[application/json], Content-Length=[118], Connection=[keep-alive], CF-Ray=[8d5d168288903961-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], frame-options=[DENY], square-version=[2024-01-18], squareup--connect--v2--common--versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/devices/codes/**], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Vary=[Accept-Encoding], Server=[cloudflare]}
Response body: {"errors": [{"code": "INTERNAL_SERVER_ERROR","detail": "An unexpected error has occurred.","category": "API_ERROR"}]}

..

2024-10-21 00:22:27 - SQUARE-TERMINAL API >>>>>>>>>> 
URI : https://connect.squareup.com/v2/devices/codes
Method : POST
Headers : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer TOKEN-REDACTED], Square-Version=[2024-01-18], Content-Length=[203]}
Request body: {"idempotency_key":"670f1c710ef632032bbea83b","device_code":{"name":"Sunset Island - Kiosk - A3288SOM0122080211050527 Square Terminal Device","location_id":"LP576VN6Y92PK","product_type":"TERMINAL_API"}}
2024-10-21 00:22:27 - SQUARE-TERMINAL API API <<<<<<<<<< Status = [500] path = [https://connect.squareup.com/v2/devices/codes]
Status code : 500
Status text : Internal Server Error
Headers : {Date=[Mon, 21 Oct 2024 00:22:27 GMT], Content-Type=[application/json], Content-Length=[118], Connection=[keep-alive], CF-Ray=[8d5d17e69c8c3961-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], frame-options=[DENY], square-version=[2024-01-18], squareup--connect--v2--common--versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/devices/codes/**], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Vary=[Accept-Encoding], Server=[cloudflare]}
Response body: {"errors": [{"code": "INTERNAL_SERVER_ERROR","detail": "An unexpected error has occurred.","category": "API_ERROR"}]}

```

Merchant ID: LP576VN6Y92PK  
Any leads on as to why this seems to be happening?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [October 22, 2024, 4:38pm UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/2 "2024-10-22T16:38:56Z")

</div>

I see the errors in the logs and have reached out to the team. I’ll be sure to update you when I hear from them. 🙂

---

<div class="post-metadata">

**Author:** ![nHiRanZ](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nHiRanZ](https://developer.squareup.com/forums/u/nHiRanZ)\
**Post date:** [October 29, 2024, 6:58am UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/3 "2024-10-29T06:58:12Z")

</div>

Hi Bryan,

Is there any update on this? We’re stuck with this merchant as we can’t complete device pairing and the onboarding process.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [October 29, 2024, 4:15pm UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/4 "2024-10-29T16:15:02Z")

</div>

This should be fixed now. Is the seller still getting the error? If so can you try it with a different `idempotency_key`. 🙂

---

<div class="post-metadata">

**Author:** ![nHiRanZ](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nHiRanZ](https://developer.squareup.com/forums/u/nHiRanZ)\
**Post date:** [October 30, 2024, 8:38am UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/5 "2024-10-30T08:38:13Z")

</div>

Hi Bryan,

We tried again but we seem to get an empty code.

**Request:**

> 2024-10-30 00:20:41 - SQUARE-TERMINAL API \>\>\>\>\>\>\>\>\>\>  
> URI : [https://connect.squareup.com/v2/devices/codes](https://connect.squareup.com/v2/devices/codes)  
> Method : POST  
> Headers : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer ACCESS\_TOKEN], Square-Version=[2024-01-18], Content-Length=[203]}  
> Request body: {“idempotency\_key”:“67217bc90ef632032bbea8a9”,“device\_code”:{“name”:“Sunset Island - Kiosk - A3288SOM0122080211050527 Square Terminal Device”,“location\_id”:“LP576VN6Y92PK”,“product\_type”:“TERMINAL\_API”}}

**Response:**

> 2024-10-30 00:20:41 - SQUARE-TERMINAL API API \<\<\<\<\<\<\<\<\<\< Status = [200] path = [[https://connect.squareup.com/v2/devices/codes](https://connect.squareup.com/v2/devices/codes)]  
> Status code : 200  
> Status text : OK  
> Headers : {Date=[Wed, 30 Oct 2024 00:20:41 GMT], Content-Type=[application/json], Connection=[keep-alive], CF-Ray=[8da73dacafa1c973-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], Vary=[Accept-Encoding], frame-options=[DENY], square-version=[2024-01-18], squareup–connect–v2–common–versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/devices/codes/\*\*], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Server=[cloudflare]}  
> Response body: {“device\_code”: {“id”: “DMGCWMFRRC04S”,“name”: “Sunset Island - Kiosk - A3288SOM0122080211050527 Square Terminal Device”,“code”: “”,“product\_type”: “TERMINAL\_API”,“location\_id”: “LP576VN6Y92PK”,“pair\_by”: “2024-10-30T00:25:26.000Z”,“created\_at”: “2024-10-30T00:20:26.000Z”,“status”: “UNPAIRED”,“status\_changed\_at”: “2024-10-30T00:20:26.000Z”}}

We changed the `idempotency_key` as you advised but the `code` value was empty. Why is this?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [October 30, 2024, 5:52pm UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/6 "2024-10-30T17:52:24Z")

</div>

I just checked the your [API Logs](https://developer.squareup.com/apps/sq0idp-TpHen_F96miOUr07zsUKTw/log) and I see that we returned the code in the API response. Is your application correctly handling the response? 🙂

---

<div class="post-metadata">

**Author:** ![nHiRanZ](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nHiRanZ](https://developer.squareup.com/forums/u/nHiRanZ)\
**Post date:** [October 31, 2024, 4:43am UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/7 "2024-10-31T04:43:13Z")

</div>

![Screenshot from 2024-10-31 10-11-30](https://global.discourse-cdn.com/square/original/2X/f/ffc838643b14289f180541e7cded31d4e71c0f48.png)

Hi Bryan, `code` value seems to be empty. This seems to happen only for this particular merchant only as well.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [October 31, 2024, 2:17pm UTC](https://developer.squareup.com/forums/t/server-error-on-requesting-code-to-pair-terminal-api/19253/8 "2024-10-31T14:17:07Z")

</div>

If you call [GetDeviceCode](https://developer.squareup.com/reference/square/devices-api/get-device-code) with the `id` is it still empty? 🙂
