MCPcopy Create free account
hub / github.com/algolia/cli / GetApplication

Method GetApplication

api/dashboard/client.go:271–302  ·  view source on GitHub ↗

GetApplication returns a single application by its ID.

(accessToken, appID string)

Source from the content-addressed store, hash-verified

269
270// GetApplication returns a single application by its ID.
271func (c *Client) GetApplication(accessToken, appID string) (*Application, error) {
272 req, err := http.NewRequest(
273 http.MethodGet,
274 c.APIURL+"/1/application/"+url.PathEscape(appID),
275 nil,
276 )
277 if err != nil {
278 return nil, err
279 }
280 c.setAPIHeaders(req, accessToken)
281
282 resp, err := c.client.Do(req)
283 if err != nil {
284 return nil, fmt.Errorf("get application request failed: %w", err)
285 }
286 defer resp.Body.Close()
287
288 if resp.StatusCode == http.StatusUnauthorized {
289 return nil, ErrSessionExpired
290 }
291 if resp.StatusCode != http.StatusOK {
292 return nil, fmt.Errorf("get application failed with status: %d", resp.StatusCode)
293 }
294
295 var singleResp SingleApplicationResponse
296 if err := json.NewDecoder(resp.Body).Decode(&singleResp); err != nil {
297 return nil, fmt.Errorf("failed to parse application response: %w", err)
298 }
299
300 app := singleResp.Data.toApplication()
301 return &app, nil
302}
303
304// CreateApplication creates a new application for the authenticated user.
305func (c *Client) CreateApplication(accessToken, region, name string) (*Application, error) {

Callers 3

fetchApplicationFunction · 0.80

Calls 4

setAPIHeadersMethod · 0.95
toApplicationMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by 2