Error using Open API

Error using Open API

Error using Open API
Error using Open API
2025-05-16 16:17:19 - last edited 2025-05-23 09:12:20
Model: OC200  
Hardware Version: V2
Firmware Version: 2.17.6 Build 20241101 Rel.44787

Hello,

 

I'm discovering OC200's OpenAPI interface with the Python code bellow:

 

OMADAHOST = '192.168.1.1'

OMADAPORT = 443

OMADAC_ID = 'xxx'

CLIENT_ID = 'xxx'

CLIENT_SECRET = 'xxx'

 

#curl "https://localhost:8043/openapi/authorize/token?grant_type=client_credentials" -H 'content-type:application/json' -d '{"omadacId": "de382a0e78f4deb681f3128c3e75dbd1", "client_id": "185586e0df424f5ea938de13cba91e01", "client_secret": "767372a5258a4fc1a03c57f3d071fc35"}' -X POST -i -k --insecure

 

headers0 = {'content-type': 'application/json'}
payload0 = json.dumps({'omadacId': OMADAC_ID, 'client_id': CLIENT_ID, 'client_secret': CLIENT_SECRET})
URL0 = f'https://{OMADAHOST}:{OMADAPORT}/openapi/authorize/token?grant_type=client_credentials'
toto = s.post(URL0, headers=headers0, data=payload0, verify=False)
print(toto.json())

 

 

I've got the following result:

{'errorCode': -44106, 'msg': 'The Client Id Or Client Secret is Invalid.'}

 

The values I used for OMADAC_ID, CLIENT_ID and CLIENT_SECRET where copied-pasted from Platform Integration web page.

 

At the same time, I can successfully log in (see [1]) and get an authorization code ([2]) but I can't also get any token [3]) with the authorization code I previously got.

I created a second API App and got the same results proving I either made a mistake while copying OMADAC_ID, CLIENT_ID and CLIENT_SECRET  or there is something wrong elsewhere.

 

Example URL are:

[1]

curl "https://localhost:8043/openapi/authorize/login?client_id=38f2d1b616434374b3f3215246f39940&omadac_id=beed48c7a2b0ea97c9698408843119f3" -H 'content-type:application/json' -d '{"username":"admin","password":"tplink123"}' -X POST -i -k --insecure

 

[2]

https://localhost:8043/openapi/authorize/code?client_id=29f2fdbeb5a84d50b9b1cdd08cd1a3ff&omadac_id=de382a0e78f4deb681f3128c3e75dbd1&response_type=code" -H 'content-type:application/json' -H 'Csrf-Token:ae6b935c92cf4b1b9f3eb852e20ed2b8' -H 'Cookie:TPOMADA_SESSIONID=9cb86bf3a99e48a59e4f3bb464a3c443' -X POST -i -k --insecure

 

[3]

curl "https://localhost:8043/openapi/authorize/token?grant_type=authorization_code&code=OC-y8fyWAyICCqCWw44Oi9GeSr7fQIKHg7g" -H 'content-type:application/json' -d '{"client_id": "29f2fdbeb5a84d50b9b1cdd08cd1a3ff", "client_secret": "cf6b13af0dd045628c9f05f088eb5493"}' -X POST -i -k --insecure

 

What am I doing wrong ? Any suggestion ?

  0      
  0      
#1
Options
1 Accepted Solution
Re:Error using Open API-Solution
2025-05-23 09:12:12 - last edited 2025-05-23 09:12:20

Hi  @Oliv2831 

 

The URLs for the two modes are different. 

 

Please refer to the online API document and configure again:

Recommended Solution
  0  
  0  
#5
Options
7 Reply
Re:Error using Open API
2025-05-18 08:08:56 - last edited 2025-05-18 08:11:19

your body seems to be wrong.

curl 'https://XXX.com:8043/openapi/authorize/token?grant_type=client_credentials' \

--header 'Content-Type: application/json' \

--data '{ "omadacId":"xxx", "client_id":"xxxx", "client_secret":"xxx" }'

 

 

The result will give you the result of accessToken. something like this below:

{

"errorCode": 0,

"msg": "Open API Get Access Token successfully.",

"result": {

"accessToken": "AT-XXXXXXXXXXXXXXX",

"tokenType": "bearer",

"expiresIn": 7200,

"refreshToken": "RT-XXXXXXXXXXXX"

}

}

  0  
  0  
#2
Options
Re:Error using Open API
2025-05-21 14:11:16

  @Wifi-freak 

 

Thank you for replying.

 

1. Which part the request body seems wrong, precisely ? If I'm not mistaken, the "payload0 = ..." should produce the expected body, with double quotes, escaping, ...

 

2. Have you successfully requested an authorization code ? If positive

2.1 Which tools did you use ?

2.2 Did you directly requested this authorization code providing OMADAC_ID, CLIENT_ID and CLIENT_SECRET or did you provide a token ?

 

 

 

  0  
  0  
#3
Options
Re:Error using Open API
2025-05-21 14:53:15

  @Wifi-freak 

 

I could at last get a successful response using Open API.

This time, I used an OC300 controller and I used a "Client Mode" configured Application instead of an "Authorization Code Mode" app.

 

Here is the redacted reply I got:

{'errorCode': 0, 'msg': 'Open API Get Access Token successfully.', 'result': {'accessToken': 'AT-lrKA7yfo4xphxxx, 'tokenType': 'bearer', 'expiresIn': 7200, 'refreshToken': 'RT-JWLXt20qGxxxx'}}

 

I don't know yet:

 

  1. If I can do anything useful with this accessToken
  2. If this can be ported to an OC200 controller
  3. What is the difference between "Authorization Code Mode" and "Client Mode" applications
  0  
  0  
#4
Options
Re:Error using Open API-Solution
2025-05-23 09:12:12 - last edited 2025-05-23 09:12:20

Hi  @Oliv2831 

 

The URLs for the two modes are different. 

 

Please refer to the online API document and configure again:

Recommended Solution
  0  
  0  
#5
Options
Re:Error using Open API
2025-05-23 12:22:17

Replying to my own questions:

1. I coud do some useful (though very simple) things

2. What successfully runs on OC300, also runs on OC200

 

  0  
  0  
#6
Options
Re:Error using Open API
2025-05-25 10:36:38
i successfully develop my python code using client mode in the older version. I didnt had a chance to use authorization mode but postman was working fine. in the latest version 5.15.24.14 , its working both client and authorization mode. The reason you need authorization mode to work too as there are certain API that you cant use in client mode. The authorization mode is kind of complicated based on the test postman.
  0  
  0  
#7
Options
Re:Error using Open API
2025-05-25 10:39:16

  @Oliv2831 

 

In client mode, you just need one API  to get the token while authorization mode, you need 3 steps to get the token.

 

  0  
  0  
#8
Options