async createListItem(twilioClient, serviceSid, listUniqueName, payload, shouldListCreate=false) {
    try {
      try {
        const result = await twilioClient.sync
          .services(serviceSid)
          .syncLists(listUniqueName)
          .syncListItems
          .create({
            data: payload
          });
        return result;
      } catch(e) {
        if(e.message === `The requested resource /Services/${serviceSid}/Lists/${listUniqueName}/Items was not found` && shouldListCreate) {
          // Create the sync list
          await twilioClient.sync
            .services(serviceSid)
            .syncLists
            .create({
              uniqueName: listUniqueName
            });
          // Reinsert the sync list item.
          const result = await this.createListItem(twilioClient, serviceSid, listUniqueName, payload, shouldListCreate);
          return result;
        } else {
          throw e;
        }
      }
    } catch(e) {
      throw e;
    }
  }
/**
   * Insert a Sync List Item in a Sync List.
   * @param {Object} twilioClient 
   * @param {String} serviceSid Sync Service SID 
   * @param {String} listUniqueName Sync List Unique Name
   * @param {Object} payload {data}
   * @param {Boolean} shouldListCreate If no list found, it will create the list. Default is false. 
   */
Insert a Sync List Item in a Sync List.
Insert a Sync List Item in a Sync List .
async createListItem(twilioClient, serviceSid, listUniqueName, payload, shouldListCreate=false) {
    try {
      try {
        const result = await twilioClient.sync
          .services(serviceSid)
          .syncLists(listUniqueName)
          .syncListItems
          .create({
            data: payload
          });
        return result;
      } catch(e) {
        if(e.message === `The requested resource /Services/${serviceSid}/Lists/${listUniqueName}/Items was not found` && shouldListCreate) {
          await twilioClient.sync
            .services(serviceSid)
            .syncLists
            .create({
              uniqueName: listUniqueName
            });
          const result = await this.createListItem(twilioClient, serviceSid, listUniqueName, payload, shouldListCreate);
          return result;
        } else {
          throw e;
        }
      }
    } catch(e) {
      throw e;
    }
  }
async createListItem ( twilioClient , serviceSid , listUniqueName , payload , shouldListCreate = false ) { try { try { const result = await twilioClient . sync . services ( serviceSid ) . syncLists ( listUniqueName ) . syncListItems . create ( { data : payload } ) ; return result ; } catch ( e ) { if ( e . message === ` ${ serviceSid } ${ listUniqueName } ` && shouldListCreate ) { await twilioClient . sync . services ( serviceSid ) . syncLists . create ( { uniqueName : listUniqueName } ) ; const result = await this . createListItem ( twilioClient , serviceSid , listUniqueName , payload , shouldListCreate ) ; return result ; } else { throw e ; } } } catch ( e ) { throw e ; } }
Insert a Sync List Item in a Sync List.
Insert a Sync List Item in a Sync List .
// Create the sync list // Reinsert the sync list item.