func (measurement *Measurement) Create(context *ctp.ApiContext) *ctp.HttpError {
	measurement.BuildLinks(context)
	measurement.Metric = ctp.ShortenLink(context.CtpBase, measurement.Metric)
	if !ctp.IsShortLink(measurement.Metric) {
		return ctp.NewBadRequestError("Invalid metric URL")
	}

	if !measurement.State.IsValid() {
		return ctp.NewBadRequestError("Invalid or missing state value")
	}

	if measurement.Result != nil {
		if err := measurementCheckResult(context, measurement); err != nil {
			return err
		}
	} else {
		if err := measurementCheckMetric(context, measurement); err != nil {
			return err
		}
	}

	if measurement.Objective != nil {
		if err := measurementObjectiveEvaluate(context, measurement); err != nil {
			return err
		}
	}

	if !ctp.CreateResource(context, "measurements", measurement) {
		return ctp.NewInternalServerError("Could not save measurement object")
	}
	return nil
}
func (trigger *Trigger) Create(context *ctp.ApiContext) *ctp.HttpError {
	trigger.BuildLinks(context)
	trigger.Measurement = ctp.ShortenLink(context.CtpBase, trigger.Measurement)
	if !ctp.IsShortLink(trigger.Measurement) {
		return ctp.NewBadRequestError("Invalid measurement URL")
	}

	ok, err := triggerCheckCondition(context, trigger, nil)
	if err != nil {
		return ctp.NewBadRequestErrorf("%s", err.Error())
	}

	if ok {
		triggerLogAndNotify(context, trigger, nil)
	}

	if !ctp.CreateResource(context, "triggers", trigger) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
	}
	return nil
}