|
|
|
|
|
|
|
|
//abstract CRUD operation for espoCRM Entity |
|
|
//abstract CRUD operation for espoCRM Entity |
|
|
|
|
|
|
|
|
func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err error) { |
|
|
func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err error) { |
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType |
|
|
|
|
|
|
|
|
url := CRMConfig.apiURL(entityType) |
|
|
jsonStr, err := postRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
jsonStr, err := postRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
entity, _ = crmRescueDuplicateCreate(err, entityType) |
|
|
entity, _ = crmRescueDuplicateCreate(err, entityType) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { |
|
|
func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { |
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
|
|
|
|
|
url := CRMConfig.apiEntityURL(entityType, id) |
|
|
jsonStr, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
jsonStr, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { |
|
|
func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { |
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
|
|
|
|
|
url := CRMConfig.apiEntityURL(entityType, id) |
|
|
jsonStr, err := putRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
jsonStr, err := putRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { |
|
|
func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { |
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
|
|
|
|
|
url := CRMConfig.apiEntityURL(entityType, id) |
|
|
resp, err := deleteRAW(url, crmBuildCommonAPIHeader()) |
|
|
resp, err := deleteRAW(url, crmBuildCommonAPIHeader()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//give an id, return json |
|
|
//give an id, return json |
|
|
func crmGetEntity(entityType string, id string) (entity interface{}, err error) { |
|
|
func crmGetEntity(entityType string, id string) (entity interface{}, err error) { |
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
|
|
|
|
|
url := CRMConfig.apiEntityURL(entityType, id) |
|
|
jsonStr, err := getRAW(url, crmBuildCommonAPIHeader()) |
|
|
jsonStr, err := getRAW(url, crmBuildCommonAPIHeader()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Println(err) |
|
|
log.Println(err) |