This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dear Support Team, I am writing to report an issue that I encountered while using the Texas Instruments (TI) Backlog API Python template.
Problem Description:
The issue pertains to the API authentication process. Although I have successfully obtained an access token, I am unable to access certain functionalities of the API, such as placing orders. This issue is impeding my ability to fully utilize the Backlog API for our operations.
Error Details:
Here is the error message I received:
PS C:\Davidlocal> & C:/Davidlocal/Apps/python.exe c:/Davidlocal/PMD_TI_BACKLOG/ExampleTI_2/python/TEST_BKGOrderConfirm.py Welcome to the backlog API example script! We will test the create and retrieve order functions using Python. Please replace lines 233-239 with your own customer credentials. Authentication Successful! Token: *MASKED* Customer sold-to ID is *MASKED*. API authentication ID is *MASKED*. Test ID for order is *MASKED*. WARNING: Unexpected HTTP status code 401. { "error": "invalid_client", "error_description": "client_id or client_secret are not correct", "error_uri": "See the full API docs at https://api-portal.ti.com/order-api-authentication" } Create Order: FAIL (90 ms). Supplier order # is MISSING. Test procedure will terminate now.
Despite successful authentication, I am unable to retrieve the quote data. (Sandbox endpoint and credentials were used.)
Please see my codes:
import json import os from datetime import datetime from TI_Backlog_API_V2 import TI_Backlog_Orders import textwrap import requests class Backlog_Example_Script(): def __init__(self, server, clientID, clientSecret, shipTo, soldTo, debug=True): self.server = server self.clientID = clientID self.clientSecret = clientSecret self.shipTo = shipTo self.soldTo = soldTo self.debug = debug self.access_token = self.retrieve_access_token() def retrieve_access_token(self): # Define your API credentials and server URL clientID = self.clientID clientSecret = self.clientSecret server = self.server auth_endpoint = f"{server}/v2/oauth/token" auth_payload = { "grant_type": "client_credentials", "client_id": clientID, "client_secret": clientSecret } try: response = requests.post(auth_endpoint, data=auth_payload) response.raise_for_status() access_token = response.json().get("access_token") if access_token: print("Authentication Successful! Token: {}".format(access_token)) return access_token else: print("Authentication Failed. No access token received.") print("Response Content:", response.content.decode()) exit(1) except requests.exceptions.RequestException as e: print(f"Authentication Error: {e}") exit(1) except Exception as e: print(f"An error occurred: {e}") exit(1) def execute(self): self.now = datetime.now() self.testID = self.now.strftime("TEST%Y%m%d%H%M%S") print("Customer sold-to ID is {}.".format(self.soldTo)) print("API authentication ID is {}.".format(self.clientID)) print("Test ID for order is {}.".format(self.testID)) steps = [ self.__create_order, self.__retrieve_order, ] for step in steps: failure = step() if failure: print("Test procedure will terminate now.") exit(1) print("Test procedure completed successfully.") def __create_order(self): self.ordersAPI = TI_Backlog_Orders( server=self.server, client_id=self.clientID, client_secret=self.clientSecret, ) self.ordersAPI.add_item_to_cart( part_number='SN7407N', quantity=10000, delivery_date=datetime(year=2027, month=6, day=15), unit_price=0.30, currency_code='USD' ) response = self.ordersAPI.post_order( customer_name='Test Customer', customer_order_number=self.testID, ship_to=self.shipTo ) outcome = self.get_result(response=response) print("Create Order: {} ({} ms).".format( outcome, int(response.elapsed.total_seconds() * 1000) )) self.supplierOrderID = "MISSING" if outcome == "PASS": self.supplierOrderID = response.json()['orders'][0]['orderNumber'] print("Supplier order # is {}.".format(self.supplierOrderID)) return outcome == "FAIL" def __retrieve_order(self): response = self.ordersAPI.retrieve_order_by_customer_number( customerOrderNumber=self.testID ) outcome = self.get_result(response=response) print("Retrieve Order: {} ({} ms).".format( outcome, int(response.elapsed.total_seconds() * 1000) )) return outcome == "FAIL" def get_result(self, response, code=200): result = 'PASS' if response.status_code == code else 'FAIL' if self.debug: print(response.text) return result print("Welcome to the backlog API example script!") print("We will test the create and retrieve order functions using Python.") print("Please replace lines 233-239 with your own customer credentials.\n") backlog_example = Backlog_Example_Script( server='https://transact-pre.ti.com/v1/oauth/accesstoken', clientID='*MASKED*', clientSecret='*MASKED*', shipTo='*MASKED*', soldTo='*MASKED*', debug=True ) backlog_example.execute()
And here is the py template i use: TI_BKG_PY_TEMPLATE
David,
I'll provide an update on Monday. In the meantime. be sure there are no spaces around your clientID or secret.
Regards,
Faye
Hi Faye, since the server reply with a token, I would assume the credentials are correct.
Hi David,
Although you successfully received a token, there may be something wrong with the URL, because the error you are receiving never made it to our side. Can you send me the full token server URL? Also, please send me the server name that you are trying to connect. Thanks!
Here is the URL: backlog_example = Backlog_Example_Script( server='transact-pre.ti.com/.../accesstoken', clientID='xxxxxx', clientSecret='xxxxxx', shipTo='xxxxxx', soldTo='xxxxxx', payerID='xxxxxx', debug=True # Set to True to always view server responses. ) Thanks!
David,
I'll send you a private chat, as I would like to get all of the code.
Hi David,
Closing this thread, per our conversation. Glad everything is working now! Just to summarize the problem and solution:
You had:
You needed:
Let us know if you need anything else.
Regards,
Faye
**Attention** This is a public forum