# Update a Segment

This API is used to update a segment for a topic

**For Segment**:

The following is the error code displayed when the Segment messaging is disabled for your tenant.

[block:code]
{
  "codes": [
    {
      "code": "{\n\n  \"code\": 70,\n\n  \"description\": \"Segment based messaging feature is not available for your tenant\"\n\n}",
      "language": "json"
    }
  ]
}
[/block]

[block:callout]
{
  "type": "info",
  "body": "To enable the Segment messaging for your tenant, contact your account manager.",
  "title": "Note"
}
[/block]

[block:callout]
{
  "type": "info",
  "title": "Know Your Endpoint",
  "body": "Based on the domain you use to log in to imiconnect, the endpoint for your API varies. See the [endpoint](https://developers.imiconnect.io/reference/endpoints) section to understand which endpoint to use for your domain."
}
[/block]

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Segment APIs",
    "version": "6.21.0"
  },
  "servers": [
    {
      "url": "https://rtm.imiconnect.io/rtmsAPI/api/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "apiKey",
        "in": "header",
        "name": "key"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/apps/{inappid}/segments/{segmentid}": {
      "put": {
        "summary": "Update a Segment",
        "description": "This API is used to update a segment for a topic",
        "operationId": "segment-apis-update",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "description": "Application/JSON",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "secretKey",
            "in": "header",
            "description": "Client key that can be accessed from your app asset configuration page on IMIconnect platform",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "inappid",
            "in": "path",
            "description": "The unique identifier corresponding to the app asset",
            "schema": {
              "type": "string"
            },
            "required": true
          },
          {
            "name": "segmentid",
            "in": "path",
            "description": "The unique identifier corresponding to your segment",
            "schema": {
              "type": "string"
            },
            "required": true
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "criteria"
                ],
                "properties": {
                  "criteria": {
                    "type": "string",
                    "description": "Criteria can be used to define a category of a segment, or it can be a combination of topics with logical operators (& | ! symbols). This is an optional parameter. You can add users to a segment and make a group without defining it's criteria . For topic-based criteria, based on the criteria condition the user base will be prepared to send push/in-app messages. For example, if Sports and News are topics, the criteria can be Sports&News *both Sports and News), or, Sports|News (either Sports or News)."
                  },
                  "name": {
                    "type": "string",
                    "description": "Name of the segment"
                  }
                }
              },
              "examples": {
                "JSON": {
                  "value": {
                    "criteria": "News & (!sports) & Entertainment & offers",
                    "name": "News And Entertainment But Not Sports And Offers"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"code\": 0,\n    \"description\": \"Success\",\n    \"trans_id\": \"71116ff7-9a1e-4a1a-9cba-7a763b304b8d\"\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0,
                      "default": 0
                    },
                    "description": {
                      "type": "string",
                      "example": "Success"
                    },
                    "trans_id": {
                      "type": "string",
                      "example": "71116ff7-9a1e-4a1a-9cba-7a763b304b8d"
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "x-readme": {
          "code-samples": [
            {
              "language": "curl",
              "code": "-X PUT https://rtm.imiconnect.io/rtmsAPI/api/v1/apps/{inappid}/segments/{{segmentid}}\n-H \"Content-Type : application/json\"\n-H \"secretKey: {secretKey}\""
            },
            {
              "language": "ruby",
              "code": "require 'httparty'\n# Create the HTTP objects and post request\nhttp = HTTParty.put(\"https://rtm.imiconnect.io/rtmsAPI/api/v1/apps/{inappid}/segments/{{segmentid}}\",\n    :headers => {'Content-Type' => 'application/json',\n                          'secretKey ' => '{secretKey}’\n            }\n)\n# Print on console\nputs http"
            },
            {
              "language": "javascript",
              "code": "var data = null;\n\nvar xhr = new XMLHttpRequest();\n\nxhr.addEventListener(\"readystatechange\", function () {\n  if (this.readyState === this.DONE) {\n    console.log(this.responseText);\n  }\n});\n\nxhr.open(\"PUT\", \" https://rtm.imiconnect.io/rtmsAPI/api/v1/apps/{inappid}/segments/{{segmentid}}\");\nxhr.setRequestHeader(\"Content-Type\", \"application/json\");\nxhr.setRequestHeader(\"secretKey\", \"{secretKey}\");\nxhr.send(data);"
            },
            {
              "language": "python",
              "code": "import requests\n\nurl = \" https://rtm.imiconnect.io/rtmsAPI/api/v1/apps/{inappid}/segments/{{segmentid}}\"\n\nheaders = {'Content-Type': 'application/json', 'secretKey': '{secretKey}’}\n\nresponse = requests.request(\"PUT\", url, headers=headers)\n\nprint(response.text)"
            }
          ],
          "samples-languages": [
            "curl",
            "ruby",
            "javascript",
            "python"
          ]
        }
      }
    }
  },
  "x-readme": {
    "headers": [
      {
        "key": "content-type",
        "value": "application/json"
      }
    ],
    "explorer-enabled": false,
    "proxy-enabled": false
  },
  "x-readme-fauxas": true,
  "_id": "6a7c6dbdd82fb949b4e99b6a:6a7c6dbdd82fb949b4e99c19"
}
```