YetiForceCompany / YetiForceCRM

Our team created for you one of the most innovative CRM systems that supports mainly business processes and allows for customization according to your needs. Be ahead of your competition and implement YetiForce!
https://yetiforce.com
Other
1.74k stars 749 forks source link

[Question] Rest API, how to setup and use? #11770

Closed Sasamous closed 4 years ago

Sasamous commented 5 years ago

Description

Hello, I can't find anywhere a documentation that say how to setup and use API, I'm about to create a connector between this CRM and an existing ERP system, but I don't know where to start from YetiForce.

I found just this partial documentation in other tickets, but isn't enough explicit.

Someone know a place where to find a documentation or can suggest me how to use YetiForce API?

Thank you in advance. 😄

mariuszkrzaczkowski commented 5 years ago

https://github.com/YetiForceCompany/YetiForceScripts/tree/master/YetiREST

Sasamous commented 5 years ago

https://github.com/YetiForceCompany/YetiForceScripts/tree/master/YetiREST

Thank you, this is very useful! I have just some questions to ask.

  1. I undestood I must create a WebService Application from YetiForce, in the field "URL" what I have to put?

  2. "$host = 'https://gitdeveloper.yetiforce.com/';" must be replace with my standard YetiForce address? e.g. "https//10.0.0.XX/" (local address while in develop)

  3. "$baseurl;" where forward?

  4. In the example "https://gitdeveloper.yetiforce.com/webservice/Users/Login", the word "webservice" must be replaced with the name of my application? e.g. "https://10.0.0.XX/YetiConnector/User/Login? I tried to ping links like this but I had only 404 errors.

Thank you in advance 😄

javjim commented 5 years ago

How to set up API:

First you need to create a web service application Integration -> Web Service application and Add key

URL is just for you to know where are you accessing from, it does not matter. name and password is what you will use as basic auth as username and password. image

then create a webservice user the user and password you create there you have to add it in the body as this image

and lastly copy the token image

in the webservice application with the copy button next to the edit one and add it like this image

tadaaaaa

mariuszkrzaczkowski commented 5 years ago

Look at this: https://learning.getpostman.com/docs/postman/collections/data_formats/#importing-openapi

OpenAPI file: https://gitdeveloper.yetiforce.com/api/Portal.json

Sasamous commented 5 years ago

Thank you @javjim but doesn't work 😞

image

mariuszkrzaczkowski commented 5 years ago

invalid URL CRM_URL/webservice/Users/Login

javjim commented 5 years ago

Yep, looks like after this, you need to first use Users/Login, and it will give you back a Token, that you need to add as a header with x-token:value and then you should be able to do stuff

Sasamous commented 5 years ago

invalid URL CRM_URL/webservice/Users/Login

I did 2 attempts

image

image

javjim commented 5 years ago

show me your yetiforce web app and web users..

Sasamous commented 5 years ago

show me your yetiforce web app and web users..

image

image

javjim commented 5 years ago

try with https://URL/webservice.php?module=Users&action=Login

Sasamous commented 5 years ago

try with https://URL/webservice.php?module=Users&action=Login

This return something image

The same result is returned also with "https://URL/webservice.php", which webservice should be activated? In webapplication it is active

mariuszkrzaczkowski commented 5 years ago

https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/tests/setup/Api.txt#L20-L21

javjim commented 5 years ago

you need to activate it in config/Api.php

Sasamous commented 5 years ago

https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/tests/setup/Api.txt#L20-L21

There was enabled only dav, I just changed with dav and webservice and now it answer "Wrong credentials", I tried with my YetiForce login credentials and with WebService User credentials but same situation.

image

image

image

Sasamous commented 5 years ago

Ok, credentials are

now the problem is "Internal Server Error":

image

where can I find a log or some suggestions to fix this problem?

CesareD commented 5 years ago

I'm following the issue. I got the same problem Internal Server Error when trying to execute login call

javjim commented 5 years ago

show the body tab

Sasamous commented 5 years ago

show the body tab

This is the body tab image

I tried API call with Demo server, it works, the login return to me the token, so maybe the problem is in my server, how can I find where is this problem?

javjim commented 5 years ago

change to form-data instead of x-www-formurlencoded

Sasamous commented 5 years ago

image

image

javjim commented 5 years ago

sorry, don't know what to tell you, verify all the steps, that is how I have it and it works properly, did you use the test and test123 username and password too? or you are just copying mine?

Sasamous commented 5 years ago

I created and used test and test123 in my Webservice Users.

I understood how it works, I tried call with the Demo server, the problem is, how can I set my YetiForce installation to answer as Demo server? I installed YetiForce correctly, following all steps and configuring my server as YetiForce requirement page ask. Maybe I have to activate something else?

mariuszkrzaczkowski commented 5 years ago

looks like you have a server configuration problem

Sasamous commented 5 years ago

looks like you have a server configuration problem

where can I see this?

mariuszkrzaczkowski commented 5 years ago

https://github.com/YetiForceCompany/YetiForceCRM/issues/11770#issuecomment-544839907

Sasamous commented 5 years ago

No sorry, I was asking: where can I check to find the problem on my configuration? Some logs? Some pages?

mariuszkrzaczkowski commented 5 years ago

check all log logs: apache FPM php crm

Sasamous commented 5 years ago

I can't find any useful information by logs. I installed the last version of YetiForce (5.2), I created an application an user for that application, I get the exactly same problems: image

image

The server configuration: image

opcache.interned_strings_buffer can't be more than 52 else page doesn't answer output_buffering is set On in both configurations but appears 1 and empty on configuration page

rskrzypczak commented 5 years ago

enable showing errors: https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/config/Debug.php#L88

Sasamous commented 5 years ago

enable showing errors: https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/config/Debug.php#L88

Response: {"status":0,"error":{"message":"2: array_merge(): Argument #1 is not an array in \/var\/www\/html\/yetiforce\/api\/webservice\/Core\/Request.php, line 43","code":200}}

Code: image

javjim commented 5 years ago

whats that x-encrypted? and also again, use form-data in body.

Sasamous commented 5 years ago

whats that x-encrypted? and also again, use form-data in body.

I don't know why it autochanges to x-www-form-urlencoded, btw ok, with form-data it works, thanks you :)

Sasamous commented 5 years ago

To close issue, I need to achieve just another answer, why works with ../"webservice.php?module=Users&action=Login" and not with "../webservice/Users/Login"? image

gogroup-official commented 5 years ago

How to get list record via api by sort order

mariuszkrzaczkowski commented 5 years ago

@ezbank you can't, but you can add it easily and quickly like this https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/api/webservice/Portal/BaseModule/RecordsList.php#L63L65

mariuszkrzaczkowski commented 5 years ago

@Sasamous check if you have it turned on mod_rewrite

Sasamous commented 5 years ago

@mariuszkrzaczkowski image

rskrzypczak commented 5 years ago

check this: https://github.com/YetiForceCompany/YetiForceCRM/issues/4154

Sasamous commented 5 years ago

check this: #4154

Perfect, this worked, I had to enable "rewrite" from mods.

I used this commands: a2enmod rewrite systemctl restart apache2

Thank you all 😄

Sasamous commented 5 years ago

So, login return token, token is accept by other api calls, but it always return {"status":0,"error":{"message":"No permissions for module","code":403}}, I tried to follow code flow and I reached this file: ../app/Privilege.php lines 91~95:

if (!Module::isModuleActive($moduleName)) {
    static::$isPermittedLevel = 'SEC_MODULE_IS_INACTIVE';
    \App\Log::trace('Exiting isPermitted method ... - yes');
    echo (Module::isModuleActive($moduleName) ? "Enabled " : "Disabled ").$moduleName; //I added this code to check problem
    return false;
}

So I get this when I try calls: image

BaseAction seems to be disabled, how can I enable it?

mariuszkrzaczkowski commented 5 years ago

Fixed https://github.com/YetiForceCompany/YetiForceCRM/commit/7d55a95d3ad78155e5494168b74464013c00812e see now https://doc.yetiforce.com/api/#/BaseAction/Api%5CPortal%5CBaseAction%5CModules%3A%3Aget

Sasamous commented 5 years ago

Fixed 7d55a95 see now https://doc.yetiforce.com/api/#/BaseAction/Api%5CPortal%5CBaseAction%5CModules%3A%3Aget

Works on demo page, but I don't have "api" folder in "public_html" folder, I'm on 5.2-Complete

image

How can I solve on my installation?

Sasamous commented 5 years ago

I could just comment the return false; and it works, but there is a better way? I don't want allow all requests without a filter

Sasamous commented 5 years ago

Cause I didn't solved my problem, I'm using demo Yetiforce for test API, but I get this error:

{"status":0,"error":{"message":"No permissions to view record","code":403,"backtrace":"#0 api\/webservice\/Portal\/BaseModule\/Record.php (62) >> Api\\Core\\Exception->__construct('No permissions to view record',403)\n#1 api\/webservice\/Core\/BaseAction.php (28) >> Api\\Portal\\BaseModule\\Record->checkPermission()\n#2 api\/webservice\/Controller.php (87) >> Api\\Core\\BaseAction->checkAction()\n#3 webservice.php (15) >> Api\\Controller->process()\n#4 public_html\/webservice.php (11) >> require('webservice.php')"}}

when I try to make this call: https://gitdeveloper.yetiforce.com/webservice.php?module=Vendors&action=Record&record=368

I'm using "demo@yetiforce.com" (administrator) user, all other calls I tried works

@mariuszkrzaczkowski

mariuszkrzaczkowski commented 5 years ago

check if user api has permissions for this record

Sasamous commented 5 years ago

check if user api has permissions for this record

Yes, the user have permissions, with that user I can see the page

image

image

Sasamous commented 5 years ago

@mariuszkrzaczkowski User have premissions, I checked and modified my demo session in different ways, nothing helps, maybe is a bug for that module? By the way, how can I get this fix https://github.com/YetiForceCompany/YetiForceCRM/issues/11770#issuecomment-545848092 on version 5.2 (Complete)? Must I uninstall everything again and download a non-stable version to get a more working (but not completely working) API system?

javjim commented 5 years ago

2 things, use as different issue for different questions, also, that issue you have is the same I am having here right? https://github.com/YetiForceCompany/YetiForceCRM/issues/11841 can you add your info there

Sasamous commented 5 years ago

Yes, it is the same response but in Demo Environment I can get ../Contacts/Record/recordID, my problem is in ../Vendors/Record/recordID