Authentication error on create Order using Python SDK

client = Client(
    access_token="ACCESS_TOKEN",
)

result = client.orders.create_order(
  body = {
    "order": {
      "location_id": "LR6QAWGZD3DDN",
      "line_items": [
        {
          "name": "tea",
          "quantity": "2",
          "item_type": "ITEM",
          "base_price_money": {
            "amount": 500,
            "currency": "JPY"
          }
        },
        {
          "name": "Coffee",
          "quantity": "3",
          "item_type": "ITEM",
          "base_price_money": {
            "amount": 300,
            "currency": "JPY"
          }
        }
      ]
    },
    "idempotency_key": "38c3fe6f-b04f-47b7-b62e-ee500ec6d06e"
  }
)

if result.is_success():
  print(result.body)
elif result.is_error():
  print(result.errors)

This code works on sandbox and with curl code but when using square python SDK 35.0.0, it throws following error.

[{'category': 'AUTHENTICATION_ERROR', 'code': 'UNAUTHORIZED', 'detail': 'This request could not be authorized.'}]

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
https://developer.squareup.com/docs/orders-api/create-orders

Additional Documentation

Python SDK
https://developer.squareup.com/docs/sdks/python/quick-start
https://developer.squareup.com/docs/build-basics/using-rest-api

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

have checked both the docs and it is not working!

In the future please don’t share your access_token. They are secret and should never be shared. All other values are safe to share.

As for your error when calling production did you also change the base path URL and credentials to your production path and credentials? :slightly_smiling_face:

Thank you for the heads up! We appreciate your reminder regarding access tokens. :+1:

Currently, we are using a sandbox token for testing purposes. Regarding the base path URL, could you please clarify which specific URL you are referring to? Additionally, we have verified that we are using the correct sandbox token. Any guidance you can provide would be helpful. Thanks!

Yeah, of course. For production https://connect.squareup.com/... and sandbox is https://connect.squareupsandbox.com/... :slightly_smiling_face: