Forum

[SOLVED] API POST I...
 
Notifications
Retirer tout

[SOLVED] API POST Issues

10 Posts
3 Utilisateurs
0 Reactions
7,715 Vu
 Carl
(@carlc)
Posts: 18
Eminent Member
Début du sujet
 
[#5752]

Hi, i've read through the documentation for using the API and reading data is no problem, when i try and send something back is when i run into problems.
The documentation gives an example for POSTing data using PHP but i'm not a PHP expert and would preferably be doing this through cURL or PowerShell, but i'm having trouble authenticating with either a specified username:password or the encrypted API key using the phpAES tool.
Can you give any examples of using POST with the API key from the command line or any other examples i could use?
Thanks


 
Posté : 07/02/2019 8:07 pm
 Carl
(@carlc)
Posts: 18
Eminent Member
Début du sujet
 

Tested some other ways of trying to POST data but it's still failing and in the system logs it gives an error:
[V7.3.5] cause = count(): Parameter must be an array or an object that implements Countable


 
Posté : 08/02/2019 1:31 pm
(@babynus)
Posts: 14952
Membre Admin
 

Can you please post complete error log ?


 
Posté : 08/02/2019 1:47 pm
 Carl
(@carlc)
Posts: 18
Eminent Member
Début du sujet
 

Thanks for looking into this - i resolved the "countable" error in the api/index.php file but i still can't POST or PUT anything.
The error message i receive now is: error: invalid API query, message: ' ' is not a known object class

System log:
2019-02-08 11:19:29.566 ===== TRACE ===== NEW CONNECTED USER 'admin'
2019-02-08 11:26:56.204 ===== TRACE ===== API : mode=GET user=admin, id=1, profile=1
2019-02-08 11:27:42.281 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:27:42.283 ** ERROR ** [V7.3.5] ERROR **
2019-02-08 11:27:42.283
** ERROR ** [V7.3.5] on file 'C:xampphtdocsapiindex.php' at line (231)
2019-02-08 11:27:42.284
** ERROR ** [V7.3.5] cause = count(): Parameter must be an array or an object that implements Countable
2019-02-08 11:27:53.307 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:27:53.308
** ERROR ** [V7.3.5] ERROR **
2019-02-08 11:27:53.308 ** ERROR ** [V7.3.5] on file 'C:xampphtdocsapiindex.php' at line (231)
2019-02-08 11:27:53.309 ** ERROR ** [V7.3.5] cause = count(): Parameter must be an array or an object that implements Countable
2019-02-08 11:28:51.582 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:28:51.583 ** ERROR ** [V7.3.5] ERROR **
2019-02-08 11:28:51.584
** ERROR ** [V7.3.5] on file 'C:xampphtdocsapiindex.php' at line (231)
2019-02-08 11:28:51.584
** ERROR ** [V7.3.5] cause = count(): Parameter must be an array or an object that implements Countable
2019-02-08 11:35:20.502 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:35:20.503
** ERROR ** [V7.3.5] ERROR **
2019-02-08 11:35:20.504 ** ERROR ** [V7.3.5] on file 'C:xampphtdocsapiindex.php' at line (231)
2019-02-08 11:35:20.504 ** ERROR ** [V7.3.5] cause = count(): Parameter must be an array or an object that implements Countable
2019-02-08 11:43:47.062 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:44:48.395 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:45:05.462 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1
2019-02-08 11:45:15.687 ===== TRACE ===== API : mode=POST user=admin, id=1, profile=1

Apache Log:
[Fri Feb 08 10:16:56.924283 2019] [mpm_winnt:notice] [pid 13976:tid 740] AH00456: Apache Lounge VC15 Server built: Jul 11 2018 12:13:24
[Fri Feb 08 10:16:56.924283 2019] [core:notice] [pid 13976:tid 740] AH00094: Command line: 'c:\xampp\apache\bin\httpd.exe -d C:/xampp/apache'
[Fri Feb 08 10:16:56.932326 2019] [mpm_winnt:notice] [pid 13976:tid 740] AH00418: Parent: Created child process 4340
[Fri Feb 08 10:16:57.450214 2019] [ssl:warn] [pid 4340:tid 692] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Feb 08 10:16:57.489689 2019] [ssl:warn] [pid 4340:tid 692] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Feb 08 10:16:57.520244 2019] [mpm_winnt:notice] [pid 4340:tid 692] AH00354: Child: Starting 150 worker threads.
[Fri Feb 08 10:20:47.519743 2019] [auth_basic:error] [pid 4340:tid 1960] [client ::1:58597] AH01618: user apidata not found: /api/UpdateID1.php
[Fri Feb 08 10:20:56.788060 2019] [auth_basic:error] [pid 4340:tid 1960] [client ::1:58603] AH01618: user apidata not found: /api/UpdateID1.php
[Fri Feb 08 10:34:41.066854 2019] [auth_basic:error] [pid 4340:tid 1960] [client ::1:58930] AH01618: user ProjeQtOr not found: /api/activity/all
[Fri Feb 08 10:35:04.244502 2019] [auth_basic:error] [pid 4340:tid 1980] [client ::1:58931] AH01618: user ProjeQtOr not found: /api/activity


 
Posté : 08/02/2019 1:53 pm
(@babynus)
Posts: 14952
Membre Admin
 

Hi

Issue on file 'C:xampphtdocsapiindex.php' at line (231) is fixed
Fix is to replace line 88 in api/index.php from

if (count($split>1)) {

to

if (count($split)>0) {

NB if you fixed with

if (count($split)>1) {

it may generate the issue on non existing class


 
Posté : 08/02/2019 5:29 pm
 Carl
(@carlc)
Posts: 18
Eminent Member
Début du sujet
 

Thanks, i've fixed that but it didn't make any difference - i still get the error: {"error":"invalid API query", "message":"'data' missing for method POST"}

I've tried passing the data through using every way i know of but it gives the same error every time, clearly something isn't right but i can't work out where or how.
When i try to use cURL with other API's it works fine but when i try and give data using "-d {json data}" the Projeqtor API says the data is missing.


 
Posté : 08/02/2019 5:40 pm
(@babynus)
Posts: 14952
Membre Admin
 

Look at exemples.
Data miust be passed in json format, encrypted with API key


 
Posté : 08/02/2019 5:45 pm
 Carl
(@carlc)
Posts: 18
Eminent Member
Début du sujet
 

I read the examples and old user manual but those are all for using the API with PHP code which i don't know so i need to do it another way.
I can successfully use cURL and Invoke-WebRequest (powershell) to GET and POST to other API's but i don't understand why the same methods won't work with Projeqtor.

You mention the data has to be encrypted with the API key but i can't find any documentation or examples which show how to do this - except your PHP example.
If there are other examples i have missed please let me know and i'll have a read through them.


 
Posté : 08/02/2019 5:51 pm
 Carl
(@carlc)
Posts: 18
Eminent Member
Début du sujet
 

Figured this out and now have a workable command-line version of cURL which is successfully doing both GET and POST.

I think the problem was a combination of:
1) the wrong key length (i've changed it to 256 instead of 128)
2) JSON data wasn't encrypted quite right (don't know how but i pulled it apart, re-encrypted it and now it works)
3) Wrong credentials used for writing (even though the same username/password worked fine for reading)


 
Posté : 08/02/2019 6:08 pm
(@caie_guens)
Posts: 10
Active Member
 

HI
with a length of 128, I have the same error message.
If you'll have a full doc, i think I missed somthig.
thanks.
Guenole


 
Posté : 28/02/2025 6:16 pm
Share:
Retour en haut