Splynx API Create User and assign Internet Tariff

Hi there, I have successfully got wordpress gravity form submission to create users in Splynx but I am having trouble getting it to assign existing Tariffs.

See my code below, however I can confirm that the correct name of the internet tariff is coming through to the splynx API because I see it in the API log.
"internet_tariffs FTTB 50/20|89.99"
I have tried making this the Internet Tariff title and the name and neither seem to work
Is this because there are additional fields that are required to be set when assigning a tariff?

add_action( ‘gform_after_submission’, ‘post_to_third_party’, 10, 2 );
function post_to_third_party( $entry, $form ) {
$firstname = rgpost( ‘input_3_3’ );
$surname = rgpost( ‘input_3_6’ );
$phone = rgpost( ‘input_4’ );
$email = rgpost( ‘input_5’ );
$street = rgpost( ‘input_15_2’ );
$city = rgpost( ‘input_15_3’ );
$zipcode = rgpost( ‘input_15_5’ );
$internet_plan = rgpost( ‘input_19’ );
$location = rgpost( ‘input_21’ );

include ‘SplynxApi.php’;

$api_url = ‘http://xxxxxxxx/’; // please set your Splynx URL

$key = “xxxxxxxxxx”; // please set your key
$secret = “xxxxxxxxxxx”; // please set your secret

// don’t forget to add permissions to API Key, for changing locations.

$api = new SplynxAPI($api_url, $key, $secret);

$locationsApiUrl = “admin/administration/locations”;
$customersApiUrl = “admin/customers/customer?” . http_build_query($search);

print “Create Customers\n”;
$result = $api->api_call_post($customersApiUrl,
array(
‘name’ => $firstname . ’ ’ . $surname,
‘login’ => $email,
‘category’ => ‘person’,
‘phone’ => $phone,
‘location_id’ => $location,
‘partner_id’ => ‘1’,
‘street_1’ => $street,
‘zip_code’ => $zipcode,
‘city’ => $city,
‘status’ => ‘active’,
‘internet_tariffs’ => $internet_plan,
));

print "Result: ";
if ($result) {
print “Ok!\n”;
print_r($api->response);
$locationId = $api->response[‘id’];
} else {
print “Fail! Error code: $api->response_code\n”;
print_r($api->response);
$locationId = false;
}

Will not work,

use new call -

for creation service internet. (with tariff)

Ruslan I don’t want to create the Tariff, the Tariff already exists in Splynx.

The $internet_plan is a variable I defined above as one of my form properties.

The result of what is sent to the API is:
‘internet_tariffs’ => ‘FTTB 50/20|89.99’,

This is the name and title of my internet Tariff.

However this does not assign the internet tariff to the user?

Hello Rob_West,
Ruslan is right, you can’t create service when you try to create customer. You have to call another “api_call_post” and use another API-url “admin/customers/customer/customer_id/internet-services”.

So, it not create the Tariff !!! it create internet service!

Ok I think I understand now,
I was confused by the terminology.
So if I have an existing Tariff I want to use for new customer I am making with API, then I must make another call and create internet service for that user.

If you are able to provide an example that would really help, I am a PHP beginner and the API wiki is JSON.

Ok have a test script working, I just need to work out how to fill the customer ID with the result of the print from the newly created customer :slight_smile:

I notice the login attribute is mandatory when creating service with API. This is not mandatory when creating a service through the web interface.?

  1. You correctly receive ID:
$locationId = $api->response['id'];

2.And about “login attribute is mandatory”:
login is required field !!! and you have to input some login as on WEB and as on the API

Ahh right you are, didn’t realise login was required on WEB too because it automatically fills it in with the user’s login when adding a service I think.

So your script, will be like this one:

include 'SplynxApi.php';

$api_url = 'http://xxxxxxxx/'; // please set your Splynx URL

$key = "xxxxxxxxxx"; // please set your key
$secret = "xxxxxxxxxxx"; // please set your secret

// don't forget to add permissions to API Key, for changing locations.

$api = new SplynxAPI($api_url, $key, $secret);

$locationsApiUrl = "admin/administration/locations";
$customersApiUrl = "admin/customers/customer?" . http_build_query($search);
$urlCustom = "admin/customers/customer";

print "Create Customers\n";
$result = $api->api_call_post($customersApiUrl,
array(
'name' => $firstname . ' ' . $surname,
'category' => 'person',
'phone' => $phone,
'email' => $email,
'location_id' => $location,
'partner_id' => '1',
'street_1' => $street,
'zip_code' => $zipcode,
'city' => $city,
'status' => 'active'
));

print "Result: ";
if ($result) {
	print "Ok!\n";
	print_r($api->response);
	$customer_id = $api->response['id'];
} else {
	print "Fail! Error code: $api->response_code\n";
	print_r($api->response);
	$customer_id = false;
}

$data = [
        'main_attributes' => [
            'id' => $customer_id
        ]
];

$api->api_call_get($urlCustom.'?'.http_build_query($data));  
$curent_customer = $api->response;
$customer_login = $curent_customer[0]['login'];

$data_array = array(
	'customer_id' => $customer_id,
	'tariff_id' => 'tariff_id',
	'description' => 'tariff name',
	'quantity' => '1',
	'status' => 'active',
	'unit_price' => '20.0',
	'start_date' => '2017-06-01',
	'end_date'  => '0000-00-00',
	'login' => $customer_login
);
$result = $api->api_call_post($urlCustom.'/'.$customer_id.'/internet-services', $data_array);
if ($result) {
	//some action;
	} else {
	//some action;
}