async function createCapabilityUnlessExists(alternateId, properties) {
    const existingCaps = await SAP_DeviceManagement.apis.Capabilities.getCapabilitiesUsingGET(
        {
            tenantId: config.SAP_tenantID,
            filter: `alternateId eq '${alternateId}'`
        }
    );
    if (!(existingCaps.ok && Array.isArray(existingCaps.body))) {
        throw new Error('Lookup of existing capabilities failed!');
    }

    if (existingCaps.body.length > 0) {
        console.debug(`Capability with alternateId '${alternateId}' found, ID='${existingCaps.body[0].id}'`);
        return existingCaps.body[0].id;
    }

    // The lookup was OK, but the capability with this alternate ID was not found.
    console.info(`Creating a new capability '${alternateId}'`);
    const res = await SAP_DeviceManagement.apis.Capabilities.createCapabilityUsingPOST(
        {
            tenantId: config.SAP_tenantID,
            request: {
                alternateId,
                properties,
                name: alternateId
            }
        }
    );
    if (!res.ok) {
        throw new Error('Capability creation failed!');
    }

    console.info(`Capability '${alternateId}' created with ID='${res.body.id}'.`);
    return res.body.id;
}
/**
 * Create the Capability (essentially, a record-like data type) in SAP IoT Services if it does not exist yet.
 * @param {string} alternateId  the alternate ID of the created Capability
 * @param {!Array.<Object.<string, string>>} properties  an array of {name, dataType} objects describing fields of the record
 * @return {string}  the ID of the Capability used by SAP IoT Services
 * @throws {Error} Raises an exception when SAP IoT Service returns an error.
 */
Create the Capability (essentially, a record-like data type) in SAP IoT Services if it does not exist yet.
@param {string} alternateId  the alternate ID of the created Capability
@param {!Array.>} properties  an array of {name, dataType} objects describing fields of the record
@return {string}  the ID of the Capability used by SAP IoT Services
@throws {Error} Raises an exception when SAP IoT Service returns an error.
Create the Capability ( essentially a record - like data type ) in SAP IoT Services if it does not exist yet . @param { string } alternateId the alternate ID of the created Capability @param { !Array . > } properties an array of { name dataType } objects describing fields of the record @return { string } the ID of the Capability used by SAP IoT Services @throws { Error } Raises an exception when SAP IoT Service returns an error .
async function createCapabilityUnlessExists(alternateId, properties) {
    const existingCaps = await SAP_DeviceManagement.apis.Capabilities.getCapabilitiesUsingGET(
        {
            tenantId: config.SAP_tenantID,
            filter: `alternateId eq '${alternateId}'`
        }
    );
    if (!(existingCaps.ok && Array.isArray(existingCaps.body))) {
        throw new Error('Lookup of existing capabilities failed!');
    }
    if (existingCaps.body.length > 0) {
        console.debug(`Capability with alternateId '${alternateId}' found, ID='${existingCaps.body[0].id}'`);
        return existingCaps.body[0].id;
    }
    console.info(`Creating a new capability '${alternateId}'`);
    const res = await SAP_DeviceManagement.apis.Capabilities.createCapabilityUsingPOST(
        {
            tenantId: config.SAP_tenantID,
            request: {
                alternateId,
                properties,
                name: alternateId
            }
        }
    );
    if (!res.ok) {
        throw new Error('Capability creation failed!');
    }
    console.info(`Capability '${alternateId}' created with ID='${res.body.id}'.`);
    return res.body.id;
}
async function createCapabilityUnlessExists ( alternateId , properties ) { const existingCaps = await SAP_DeviceManagement . apis . Capabilities . getCapabilitiesUsingGET ( { tenantId : config . SAP_tenantID , filter : ` ${ alternateId } ` } ) ; if ( ! ( existingCaps . ok && Array . isArray ( existingCaps . body ) ) ) { throw new Error ( 'Lookup of existing capabilities failed!' ) ; } if ( existingCaps . body . length > 0 ) { console . debug ( ` ${ alternateId } ${ existingCaps . body [ 0 ] . id } ` ) ; return existingCaps . body [ 0 ] . id ; } console . info ( ` ${ alternateId } ` ) ; const res = await SAP_DeviceManagement . apis . Capabilities . createCapabilityUsingPOST ( { tenantId : config . SAP_tenantID , request : { alternateId , properties , name : alternateId } } ) ; if ( ! res . ok ) { throw new Error ( 'Capability creation failed!' ) ; } console . info ( ` ${ alternateId } ${ res . body . id } ` ) ; return res . body . id ; }
Create the Capability (essentially, a record-like data type) in SAP IoT Services if it does not exist yet.
Create the Capability ( essentially a record - like data type ) in SAP IoT Services if it does not exist yet .
// The lookup was OK, but the capability with this alternate ID was not found.