async upsertMapItem(twilioClient, serviceSid, mapUniqueName, payload, shouldMapCreate=false) {
    try {
      const result = await twilioClient.sync
      .services(serviceSid)
      .syncMaps(mapUniqueName)
      .syncMapItems
      .create({...payload});
      return result;
    } catch(e) {
      if(e.message === `An Item with given key already exists in the Map`) {
        // Update the Map Item.
        const {key, data} = payload;
        const result = await twilioClient.sync
        .services(serviceSid)
        .syncMaps(mapUniqueName)
        .syncMapItems(key)
        .update({data});
        return result;
      } else if(e.message === `The requested resource /Services/${serviceSid}/Maps/${mapUniqueName}/Items was not found` && shouldMapCreate) {
        // Create the sync map
        await twilioClient.sync
        .services(serviceSid)
        .syncMaps
        .create({
          uniqueName: mapUniqueName
        });
        // Reinsert the sync map item.
        const result = await this.upsertMapItem(twilioClient, serviceSid, mapUniqueName, payload, shouldMapCreate);
        return result;
      }
      throw e;
    }
  }
/**
   * Upsert a Sync Map Item in a Sync Map.
   * @param {Object} twilioClient 
   * @param {String} serviceSid Sync Service SID 
   * @param {String} mapUniqueName Sync Map Unique Name
   * @param {Object} payload {key, data}
   * @param {Boolean} shouldMapCreate If no map found, it will create the map. Default is false. 
   */
Upsert a Sync Map Item in a Sync Map.
Upsert a Sync Map Item in a Sync Map .
async upsertMapItem(twilioClient, serviceSid, mapUniqueName, payload, shouldMapCreate=false) {
    try {
      const result = await twilioClient.sync
      .services(serviceSid)
      .syncMaps(mapUniqueName)
      .syncMapItems
      .create({...payload});
      return result;
    } catch(e) {
      if(e.message === `An Item with given key already exists in the Map`) {
        const {key, data} = payload;
        const result = await twilioClient.sync
        .services(serviceSid)
        .syncMaps(mapUniqueName)
        .syncMapItems(key)
        .update({data});
        return result;
      } else if(e.message === `The requested resource /Services/${serviceSid}/Maps/${mapUniqueName}/Items was not found` && shouldMapCreate) {
        await twilioClient.sync
        .services(serviceSid)
        .syncMaps
        .create({
          uniqueName: mapUniqueName
        });
        const result = await this.upsertMapItem(twilioClient, serviceSid, mapUniqueName, payload, shouldMapCreate);
        return result;
      }
      throw e;
    }
  }
async upsertMapItem ( twilioClient , serviceSid , mapUniqueName , payload , shouldMapCreate = false ) { try { const result = await twilioClient . sync . services ( serviceSid ) . syncMaps ( mapUniqueName ) . syncMapItems . create ( { ... payload } ) ; return result ; } catch ( e ) { if ( e . message === ` ` ) { const { key , data } = payload ; const result = await twilioClient . sync . services ( serviceSid ) . syncMaps ( mapUniqueName ) . syncMapItems ( key ) . update ( { data } ) ; return result ; } else if ( e . message === ` ${ serviceSid } ${ mapUniqueName } ` && shouldMapCreate ) { await twilioClient . sync . services ( serviceSid ) . syncMaps . create ( { uniqueName : mapUniqueName } ) ; const result = await this . upsertMapItem ( twilioClient , serviceSid , mapUniqueName , payload , shouldMapCreate ) ; return result ; } throw e ; } }
Upsert a Sync Map Item in a Sync Map.
Upsert a Sync Map Item in a Sync Map .
// Update the Map Item. // Create the sync map // Reinsert the sync map item.