# Error while using Maapi\_Create to load default configuration into CDB

**URL:** <https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650>\
**Category:** CDB and CDB API\
**Created:** [November 16, 2017, 7:07am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650 "2017-11-16T07:07:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yvk](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yvk](https://dmap-community.ductus.global/u/yvk)\
**Post date:** [November 16, 2017, 7:07am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/1 "2017-11-16T07:07:21Z")

</div>

we are using Maapi API’s (maapi\_create,maapi\_setelem) to load default configuration into CDB.  
But we are facing one issue. some of the list elements of our yang model are dynamically  
created so we should not have any list element after loading Default configuration.

whenever we try to load without creating this list element into CDB we are getting this error: CONFD\_ERR\_BAD\_KEYREF  
if we set these elements then objects are successfully loaded into CDB.

IMO it means that since we have not set some of the list elements we are receiving this error.  
Is there any way we can bypass this so that our element creation will be successful ??

**Maapi Code Flow :**

```
maapi_create(sock,th,/wavelengths/wl{first});
maapi_set_elem(sock,th,/wavelengths/wl/name,w1)

```

- 

**Sample yang Model :**

```
container wavelengths {
        list wl {
          key name;
          leaf name {
           type string;
         }
         container connections { **---> Dynamic Entries which should not be loaded into CDB**
          list connection { 
            key id;
            leaf id {
             type uint32;
            }
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [November 16, 2017, 8:08am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/2 "2017-11-16T08:08:33Z")

</div>

Hi,

I am not sure what the maapi\_set\_elem is supposed to do here?

Example using the confd\_cmd and confd\_load tools:

```auto
$ confd_cmd -d -d -c 'mcreate /wavelengths/wl{"first"}'
mcreate "/wavelengths/wl{"first"}"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_CREATE /wavelengths/wl{"first"} --> CONFD_OK
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
$ confd_load -d -d -F p -p /wavelengths
TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG --> CONFD_OK
TRACE Connected (stream) to ConfD
<config xmlns="http://tail-f.com/ns/config/1.0">
  <wavelengths xmlns="http://tail-f.com/ns/example/test">
    <wl>
      <name>first</name>
    </wl>
  </wavelengths>
TRACE MAAPI_SAVE_CONFIG_RESULT --> CONFD_OK
</config>
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
$ confd_cmd -d -d -c 'mcreate /wavelengths/wl{"second"}'
mcreate "/wavelengths/wl{"second"}"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_CREATE /wavelengths/wl{"second"} --> CONFD_OK
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
$ confd_load -d -d -F p -p /wavelengths
TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG --> CONFD_OK
TRACE Connected (stream) to ConfD
<config xmlns="http://tail-f.com/ns/config/1.0">
  <wavelengths xmlns="http://tail-f.com/ns/example/test">
    <wl>
      <name>first</name>
    </wl>
    <wl>
      <name>second</name>
    </wl>
  </wavelengths>
TRACE MAAPI_SAVE_CONFIG_RESULT --> CONFD_OK
</config>
TRACE MAAPI_END_USER_SESSION --> CONFD_OK

```

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [November 16, 2017, 8:23am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/3 "2017-11-16T08:23:06Z")

</div>

When you create list entry using `maapi_create()`, you do not need to `maapi_set_elem()` for key values - this is done “automatically” on \_create() call…

I’m not sure what you mean by “loading” in this case - for what command or operation specifically you get error.

---

<div class="post-metadata">

**Author:** ![yvk](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yvk](https://dmap-community.ductus.global/u/yvk)\
**Post date:** [November 22, 2017, 6:48am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/4 "2017-11-22T06:48:35Z")

</div>

yes. you are right. `maapi_set_elem()` is not needed for updating key element but here I am using `maapi_set_elem()` to set values for leafs inside a list.

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [November 22, 2017, 6:53am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/5 "2017-11-22T06:53:15Z")

</div>

In your sample yang model there are no elements inside your lists except the key that need to be set when the list entry is created?

Example:

```auto
$ confd_cmd -d -d -c 'mcreate /wavelengths/wl{"first"}; mcreate /wavelengths/wl{"first"}/connections/connection{32}'
mcreate "/wavelengths/wl{"first"}" ; mcreate "/wavelengths/wl{"first"}/connections/connection{32}"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_CREATE /wavelengths/wl{"first"} --> CONFD_OK
TRACE MAAPI_CREATE /wavelengths/wl{"first"}/connections/connection{32} --> CONFD_OK
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK

```

---

<div class="post-metadata">

**Author:** ![yvk](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yvk](https://dmap-community.ductus.global/u/yvk)\
**Post date:** [November 22, 2017, 9:09am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/6 "2017-11-22T09:09:36Z")

</div>

Previously I was using `maapi_set_elem()` for both key element & non-key elements for a list. I think my yang example is not reflecting that part.  
I am not getting any error if i use `maapi_set_elem()` on key element of list.

My Main Query is that, is it possible to create a new entry (`/wavelengths/wl{"first"}`) in CDB without calling `maapi_create()` on `/wavelengths/wl{"first"}/connections/connection{31}` ?

I was getting `CONFD_ERR_BAD_KEYREF` error if i don’t create `connections/connection{31}` using maapi\_create. so i want to know whether is it possible or not.

I am not using `confd_load/confd_cmd` to populate these entries in CDB. I am doing it through c program. does it make any difference ?

Thanks for the Help.

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [November 22, 2017, 9:18am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/7 "2017-11-22T09:18:47Z")

</div>

hi,

it is still not completely clear when specifically, for which confd-lib procedure call/operation you get that error…

your sample yang model allows creating instance of “wavelengths/wl{first}” list.  
you don’t need to do any internal “wavelengths/wl{first}/connections/connection{31}” entry…

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [November 22, 2017, 9:36am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/8 "2017-11-22T09:36:16Z")

</div>

> [@yvk](#):
>
> I am not using confd\_load/confd\_cmd to populate these entries in CDB. I am doing it through c program. does it make any difference ?

In addition to @josephm 's comment, confd\_cmd / confd\_load are c programs too that you can use as a reference. That’s why I use them to demo how to do things. See:  
$CONFD\_DIR/src/confd/tools/confd\_cmd.c  
$CONFD\_DIR/src/confd/tools/confd\_load.c

---

<div class="post-metadata">

**Author:** ![yvk](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yvk](https://dmap-community.ductus.global/u/yvk)\
**Post date:** [November 22, 2017, 9:37am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/9 "2017-11-22T09:37:00Z")

</div>

Call Flow is as follows –

```
maapi_start_trans()
maapi_create() - wl list entry
maapi_set_elem() - for key leaf -- redundant
maapi_set_elem() - for non key leaf
maapi_apply_trans() -- getting error `CONFD_ERR_BAD_KEYREF` 

```

but if follow the below call flow then it is working –

```
maapi_start_trans()
maapi_create() - wl list entry
maapi_set_elem() - for key leaf -- redundant
maapi_set_elem() - for non key leaf
maapi_create() - connections list entry
maapi_set_elem() - for key leaf -- redundant
maapi_apply_trans() -- No Error.

```

I will try by removing the maapi\_set\_elem() on key leaf element to see whether is it working or not.

Thanks for the Reply.

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [November 22, 2017, 9:49am UTC](https://dmap-community.ductus.global/t/error-while-using-maapi-create-to-load-default-configuration-into-cdb/1650/10 "2017-11-22T09:49:18Z")

</div>

try verifying return code of each of the steps - maapi\_create()/maapi\_set\_elem()/… one of them should give you CONFD\_ERR giving closer hint on some inconsistent operation - e.g. keypath not prepared correctly etc.

if not, you may have some problem in config you are trying to “commit” due to e.g. YANG must statements failing, validation callpoints rejecting transaction, YANG “mandatory true;” statements being not fulfilled etc.
