Database creation via API

Discussion in 'Developers' Forum' started by Massimiliano Micol, Jul 22, 2021.

  1. Massimiliano Micol

    Massimiliano Micol New Member

    Good afternoon,
    I'm trying to create a database using the function $client->sites_database_add
    I'm actually creating the database, but I have an issue: apparently I can't assign a website to the created domain. Looking in the docs I saw that the above function requires a parameter named "website_id", which I'm passing and I think is correct (I'm creating the website in the same file, storing the returned id). I even tried to edit the database later, with $client->sites_database_update to add the website_id field, but I did not manage to add it.
    I'm calling the function with these parameters:
    PHP:
    Array
    (
        [
    server_id] => 1
        
    [website_id] => 18
        
    [type] => mysql
        
    [database_name] => trisdb
        
    [database_user_id] => 12
        
    [database_charset] => UTF8
        
    [remote_access] => y
        
    [remote_ips] =>
        [
    backup_interval] => none
        
    [backup_copies] => 1
        
    [active] => y
    )
    but what I get when the database is created and queried is this:
    PHP:
    Array
    (
        [
    database_id] => 11
        
    [sys_userid] => 28
        
    [sys_groupid] => 55
        
    [sys_perm_user] => riud
        
    [sys_perm_group] => riud
        
    [sys_perm_other] =>
        [
    server_id] => 1
        
    [parent_domain_id] => 0
        
    [type] => mysql
        
    [database_name] => trisdb
        
    [database_name_prefix] =>
        [
    database_quota] => 0
        
    [quota_exceeded] => n
        
    [last_quota_notification] =>
        [
    database_user_id] => 12
        
    [database_ro_user_id] => 0
        
    [database_charset] => UTF8
        
    [remote_access] => y
        
    [remote_ips] =>
        [
    backup_interval] => none
        
    [backup_copies] => 1
        
    [active] => y
    )
    As you can see apparently there is no "website_id" field. What am I doing wrong?
     
  2. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    What are the results of you create a site and database via the ui as a comparison?
     
  3. Massimiliano Micol

    Massimiliano Micol New Member

    I dug a bit further and I found that the function $client->sites_database_add does not require a "website_id" field instead of what is written in the docs. To assign the database I had to give to the field "parent_domain_id" the website id, and now it's linked and is working as intended
     
    Last edited: Jul 22, 2021
    Jesse Norell likes this.

Share This Page