# Genieacs API - addObject doesn't return instance ID

**URL:** <https://forum.genieacs.com/t/genieacs-api-addobject-doesnt-return-instance-id/361>\
**Category:** Uncategorized\
**Created:** [October 16, 2019, 1:03am UTC](https://forum.genieacs.com/t/genieacs-api-addobject-doesnt-return-instance-id/361 "2019-10-16T01:03:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![akcoder](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/akcoder/32/11_2.png) [@akcoder](https://forum.genieacs.com/u/akcoder)\
**Post date:** [October 16, 2019, 5:56pm UTC](https://forum.genieacs.com/t/genieacs-api-addobject-doesnt-return-instance-id/361/2 "2019-10-16T17:56:49Z")

</div>

So… I’ve battled this exact use case before and I can tell you to quote Steve Jobs, your “holding (doing) it wrong” 🙂

First off, because of the underlying async nature of how communication with the CPE occurs, its going to be near impossible to get the instance ID. Genie does a good job of trying to make the async communication with the CPE appear synchronous, but at a fundamental level the addObject could actually occur at any point in time (now, or hours from now).

So here is how you want to handle this.

Create a provision script called [PortForwards using this code](https://gist.github.com/akcoder/0cd5b3312fca5ca989a07078fd5e27be).

Create a preset like so called UpdatePortForwards with a tag precondition of “UpdatePortForwards” and under configuration add a provision script and put in “PortForwards”.

In your genieacs/config/ext folder put the [cpe-config.js file using this code](https://gist.github.com/akcoder/88cb85410f971bc322a69dff0e632d31).

Have your API return code that looks like this:

```
[
  {
    "InternalClient": "192.168.1.2",
    "PortMappingDescription": "Foo",
    "PortMappingProtocol": "TCP",
    "PortMappingEnabled": 1,
    "RemoteHost": "",
    "InternalPort": 8080,
    "ExternalPort": 8080,
    "ExternalPortEndRange": 8080
  }
]

```

Where each array entry maps directly to a key/value for an instance in PortMapping.

Finally, add the tag `UpdatePortForwards` to the CPE in GenieACS and initiate a connection with the CPE.

While this whole process may seem more complicated initially, it will always ensure the port forwarding instances are created/deleted as needed.

I’ve had this code in production for two years with absolutely zero issues.

---

_[View the full topic](https://forum.genieacs.com/t/genieacs-api-addobject-doesnt-return-instance-id/361)._
