MashterSoporte Posted April 6, 2016 Report Posted April 6, 2016 I need import from other database my customers list to clients in blesta, but i want do it from API, how can i do it? (I'm sorry, but I know a little english) Quote
0 Tyson Posted April 7, 2016 Report Posted April 7, 2016 Have you read the documentation regarding the API? Have you tried to use the API SDK to help simplify making API calls? Have you looked at the source documention regarding the creation of clients? You can make a call to Clients::create to create a user account, client account, and contact in Blesta by passing all of the necessary information from data you retrieve from your current customer list. Quote
0 MashterSoporte Posted April 7, 2016 Author Report Posted April 7, 2016 Have you read the documentation regarding the API? Have you tried to use the API SDK to help simplify making API calls? Have you looked at the source documention regarding the creation of clients? You can make a call to Clients::create to create a user account, client account, and contact in Blesta by passing all of the necessary information from data you retrieve from your current customer list. I downloaded the API SDK, i cant get a response, but i use a HTTP Client (Chrome Extension - Boomerang) and get a response with the clients information, i try with "http://domain.com/api/clients/add/post.json"sending the params of add client form but i get this: "{ "message": "The format requested is not supported by the server.", "response": null }" Quote
0 MashterSoporte Posted April 7, 2016 Author Report Posted April 7, 2016 What request data are you sending? I sending the same fields of the add clients form: _csrf_token first_name last_name company address1 address2 ... Here a screenshot: http://www.mediafire.com/view/ljxjd3o1tt9m4t4/blesta.png Quote
0 Tyson Posted April 7, 2016 Report Posted April 7, 2016 The screenshot shows the user interface, but not your request sent via the API. If you're making an HTTP POST request using the API SDK you downloaded, you would do so similar to the examples shown in the API SDK readme. Quote
0 MashterSoporte Posted April 7, 2016 Author Report Posted April 7, 2016 I sending to domain.com/api/clients/create.xml with method POST <?xml version="1.0" encoding="UTF-8" ?> <vars> <username>fulanito</username> <new_password>mash123</new_password> <confirm_password>mash123</confirm_password> <client_group_id>1</client_group_id> <status>active</status> <firstname>Fulanito</firstname> <last_name>De tal</last_name> <email>fulanito@email.com</email> <state>AGU</state> <country>MX</country> <zip>27000</zip> <settings> <default_currency>MXN</default_currency> <language>es_es</language> <username_type>username</username_type> <tax_id /> <tax_exempt>true</tax_exempt> <send_registration_email>false</send_registration_email> </settings> </vars> And get this response HTTP/1.1 400 "Bad Request" 1317ms Date: Thu, 07 Apr 2016 22:12:11 GMT Server: Apache/2.2.15 (CentOS) Connection: close X-Powered-By: PHP/5.3.3 Content-Length: 369 Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" ?> <clients> <message>The request cannot be fulfilled due to bad syntax.</message> <errors> <username> <empty>Por favor, introduce un nombre de usuario.</empty> </username> <new_password> <format>Por favor ingrese una contraseña de al menos 6 caracteres.</format> </new_password> </errors> <response /> </clients> Whats is wrong? Quote
0 MashterSoporte Posted April 7, 2016 Author Report Posted April 7, 2016 in the previous post i am using a Chrome extension HTTP Client (Boomerang) beacause i cant use the SDK This is my PHP Code if i use the API SDK <?php require_once 'api/blesta_api.php'; $user = "isaac"; $key = "a5-----------------0f4f"; $url = "http://domain.com/api"; $api = new BlestaApi($url, $user, $key); $args = array( 'vars' => array( 'username' => 'fulanito', 'new_password' => 'Mash.123', 'confirm_password' => 'Mash.123', 'client_group_id' => 1, 'first_name' => 'Fulanito', 'last_name' => 'De tal', 'email' => 'fulanito@moesbar.com', 'state' => 'AGU', 'country' => 'MX', 'zip' => '27000', 'settings' => array( 'default_currency' => 'MXN', 'language' => 'es_es', 'tax_exempt' => true, 'send_registration_email' => false ) ) ); $response = $api->post('clients', 'create', $args); var_dump($response); The var_dump show this: object(BlestaResponse)#2 (2) { ["raw":"BlestaResponse":private]=> string(0) "" ["response_code":"BlestaResponse":private]=> int(302) } Quote
0 Tyson Posted April 7, 2016 Report Posted April 7, 2016 Can you dump the response and any errors? i.e. print_r($response->response()); print_r($response->errors()); What you have looks like it should work to me. Are you able to perform a simpler action, like the example in the docs--fetching a user by ID? $response = $api->get("users", "get", array('user_id' => 1)); Michael 1 Quote
Question
MashterSoporte
I need import from other database my customers list to clients in blesta, but i want do it from API, how can i do it?
(I'm sorry, but I know a little english)
8 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.