Announcement

Collapse
No announcement yet.

Register New User REST API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Register New User REST API

    Hi tanya

    As I understand from this thread:

    https://forum.espocrm.com/forum/feat...m-sign-up-form

    This is how you make a post call to update new user details.

    You need to make POST a call to http://your_domain/api/v1/User

    Json that must be sent Code:

    {
    "userName": "tester",
    "lastName": "Tester",
    "firstName": "Test",
    "password": "1",
    "passwordConfirm": "1",
    "isActive": false,
    "isAdmin": false
    }

    Here is the php wrapper for the API

    https://github.com/espocrm/documenta...-client-php.md

    But I do not know where to find the API Key, Do I create it myself? If so how?

    I want to keep things simple using the php client. So can I just do the following:

    PHP Code:
    $client = new EspoApiClient('https://your-espocrm-site''USERNAME''PASSWORD');

      
    $response $client->request('POST''User', [ 'firstName' => 'Test''lastName' => 'Hello' "userName""tester""password""whatever""passwordConfirm""whatever""isActive"false"isAdmin"false ]); 
    The way that I understand it is that username and password are the super administrator's credentials?
    Last edited by Zoolean; 01-28-2019, 02:12 PM.

  • #2
    oK, so I tried the github client and it did not work... So I wrote my own code based off of the github client. It gives me an authentication failed error message.

    Error: Warning: file_get_contents(<PATH>): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in <PATH> on line 37

    This is my code


    PHP Code:

    ini_set
    ('display_errors'1);
    ini_set('display_startup_errors'1);
    error_reporting(E_ALL);


    //url

    $url 'http://<website/folder/folder>/api/v1/Lead';

    //Credentials
    $client_id  "<username>";
    $client_pass"<password>";

    //HTTP options
    $opts = array('http' =>
        array(
            
    'method'    => 'POST',
            
    'header'    => array ('Content-type: application/json''Authorization: Basic '.base64_encode("$client_id:$client_pass")),
            
    'firstName' => "hmm",
            
    'lastName' => "hmm"
        
    )
    );

    //Do request
    $context stream_context_create($opts);
    $json file_get_contents($urlfalse$context);

    $result json_decode($jsontrue);
    if(
    json_last_error() != JSON_ERROR_NONE){
        return 
    null;
    }

    print_r($result); 
    Why wont this authenticate?

    Last edited by Zoolean; 01-28-2019, 02:16 PM.

    Comment


    • #3
      Hi,

      I don't understand why you have in url "folder/folder"

      $url = 'http://espoCrm/api/v1/Lead';

      open navigator console.. make a change on a record.. look whats append .. in network xhr.. you must use this url.

      this is what I think, never use external client still.



      Comment


      • #4
        Thank you very much for your response. I found this link on the forum which provided me with a working example of the API. I tested it and it worked correctly .



        For anyone reading this, this link will be very useful.

        Comment


        • #5
          Oh one last thing. It seems the above link only works with an API key and not the user name and password. In any event, in order to create an API key, you need to add an API user from within the CRM

          Comment

          Working...
          X