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

Method UpdateApplication

api/dashboard/client.go:355–401  ·  view source on GitHub ↗

UpdateApplication renames an existing application.

(accessToken, appID, name string)

Source from the content-addressed store, hash-verified

353
354// UpdateApplication renames an existing application.
355func (c *Client) UpdateApplication(accessToken, appID, name string) (*Application, error) {
356 payload := UpdateApplicationRequest{Name: name}
357 body, err := json.Marshal(payload)
358 if err != nil {
359 return nil, err
360 }
361
362 endpoint := c.APIURL + "/1/applications/" + url.PathEscape(appID)
363 req, err := http.NewRequest(http.MethodPatch, endpoint, bytes.NewReader(body))
364 if err != nil {
365 return nil, err
366 }
367 c.setAPIHeaders(req, accessToken)
368 req.Header.Set("Content-Type", "application/json")
369
370 resp, err := c.client.Do(req)
371 if err != nil {
372 return nil, fmt.Errorf("update application request failed: %w", err)
373 }
374 defer resp.Body.Close()
375
376 if resp.StatusCode == http.StatusUnauthorized {
377 return nil, ErrSessionExpired
378 }
379
380 if resp.StatusCode != http.StatusOK {
381 respBody, _ := io.ReadAll(resp.Body)
382 if resp.StatusCode == http.StatusNotFound {
383 return nil, fmt.Errorf(
384 "no existing application found; select one using 'algolia application select' or create a new one with 'algolia application create'",
385 )
386 }
387 return nil, fmt.Errorf(
388 "update application failed with status %d: %s",
389 resp.StatusCode,
390 string(respBody),
391 )
392 }
393
394 var singleResp SingleApplicationResponse
395 if err := json.NewDecoder(resp.Body).Decode(&singleResp); err != nil {
396 return nil, fmt.Errorf("failed to parse application response: %w", err)
397 }
398
399 app := singleResp.Data.toApplication()
400 return &app, nil
401}
402
403// GetSelfServePlans returns the available plans
404func (c *Client) GetSelfServePlans(accessToken string) ([]Plan, error) {

Callers 4

runUpdateCmdFunction · 0.80

Calls 5

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