Skip to content

Commit ffc3992

Browse files
author
lleadbet
committed
fixing #119
1 parent 9ad36fe commit ffc3992

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

internal/api/api.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewRequest(method string, path string, queryParameters []string, body []byt
4545
if err != nil {
4646
fmt.Println("Error fetching client information", err.Error())
4747
}
48-
48+
isFirstRun := true
4949
for {
5050
var apiResponse models.APIResponse
5151

@@ -101,25 +101,30 @@ func NewRequest(method string, path string, queryParameters []string, body []byt
101101
return
102102
}
103103

104-
data.Template = apiResponse.Template
104+
if isFirstRun {
105+
data = apiResponse
106+
isFirstRun = false
107+
}
105108

106109
if resp.StatusCode > 299 || resp.StatusCode < 200 {
107110
data = apiResponse
108111
break
109112
}
110-
113+
if data.Data == nil {
114+
break
115+
}
111116
d := data.Data.([]interface{})
112117
if strings.Contains(path, "schedule") || apiResponse.Data == nil {
113118
data.Data = append(d, apiResponse.Data)
114119
} else {
115120
data.Data = append(d, apiResponse.Data.([]interface{})...)
116121
}
117122

118-
if apiResponse.Pagination == nil || *&apiResponse.Pagination.Cursor == "" {
123+
if apiResponse.Pagination == nil || apiResponse.Pagination.Cursor == "" {
119124
break
120125
}
121126

122-
if autopaginate == false {
127+
if !autopaginate {
123128
data.Pagination = &models.APIPagination{
124129
Cursor: apiResponse.Pagination.Cursor,
125130
}
@@ -130,7 +135,6 @@ func NewRequest(method string, path string, queryParameters []string, body []byt
130135
break
131136
}
132137
cursor = apiResponse.Pagination.Cursor
133-
134138
}
135139

136140
if data.Data == nil {

0 commit comments

Comments
 (0)