Skip to content

Instantly share code, notes, and snippets.

@printer-gmg
Last active May 22, 2017 13:25
Show Gist options
  • Select an option

  • Save printer-gmg/2eb864dcf73266b02b94e966304928a2 to your computer and use it in GitHub Desktop.

Select an option

Save printer-gmg/2eb864dcf73266b02b94e966304928a2 to your computer and use it in GitHub Desktop.

Typed tags endpoint examples

Creating a schema

POST api.kinja.com/api/core/typedtag/schema

{
  "schemaId" : 100,
  "schema": {
    "A": {
      "B" : {
        "C" : {}
      }
    },
    "D": {}
  }
}

Getting a schema

GET api.kinja.com/api/core/typedtag/schema?schemaId=100

Validating tags for a schema

POST api.kinja.com/api/core/typedtag/validate

Valid tag set

post body:

{
  "schemaId" : 100,
  "typedTags" : [
    {
      "tagType": "A",
      "tagValue": "foo"
    },
    {
      "tagType": "B",
      "tagValue": "bar"
    },
    {
      "tagType": "C",
      "tagValue": "foobar"
    },
    {
      "tagType": "D",
      "tagValue": "baz"
    }
  ]
}

response:

{
  "meta": {
    "error": null,
    "warnings": []
  },
  "data": true
}

Valid tag set

note that not all tags are defined, but if a tag is specified, all ancestors are also specified

post body:

{
  "schemaId" : 100,
  "typedTags" : [
    {
      "tagType": "A",
      "tagValue": "foo"
    },
    {
      "tagType": "B",
      "tagValue": "bar"
    }
  ]
}

response:

{
  "meta": {
    "error": null,
    "warnings": []
  },
  "data": true
}

Invalid tag set

post body:

{
  "schemaId" : 100,
  "typedTags" : [
    {
      "tagType": "C",
      "tagValue": "foobar"
    },
    {
      "tagType": "D",
      "tagValue": "baz"
    }
  ]
}

response:

{
  "meta": {
    "error": null,
    "warnings": [
      {
        "message": "Tags with types A, B are missing from the provided tag set. These tags are required because they are ancestors of the tag: C.",
        "code": "MISSING_TYPED_TAG"
      }
    ]
  },
  "data": false
}

Invalid tag set

post body:

{
  "schemaId" : 100,
  "typedTags" : [
    {
      "tagType": "B",
      "tagValue": "bar"
    },
    {
      "tagType": "C",
      "tagValue": "foobar"
    },
    {
      "tagType": "D",
      "tagValue": "baz"
    }
  ]
}

response:

{
  "meta": {
    "error": null,
    "warnings": [
      {
        "message": "Tags with types A are missing from the provided tag set. These tags are required because they are ancestors of the tag: B.",
        "code": "MISSING_TYPED_TAG"
      },
      {
        "message": "Tags with types A are missing from the provided tag set. These tags are required because they are ancestors of the tag: C.",
        "code": "MISSING_TYPED_TAG"
      }
    ]
  },
  "data": false
}

Invalid tag set

post body:

{
  "schemaId" : 100,
  "typedTags" : [
    {
      "tagType": "X",
      "tagValue": "bar"
    },
    {
      "tagType": "C",
      "tagValue": "foobar"
    },
    {
      "tagType": "D",
      "tagValue": "baz"
    }
  ]
}

response:

{
  "meta": {
    "error": null,
    "warnings": [
      {
       "message": "Unknown tag type: X.",
       "code": "UNKNOWN_TAG_TYPE"
      },
      {
        "message": "Tags with types A, B are missing from the provided tag set. These tags are required because they are ancestors of the tag: C.",
        "code": "MISSING_TYPED_TAG"
      }
    ]
  },
  "data": false
}

Invalid schema id

post body:

{
  "schemaId" : 99,
  "typedTags" : [
    {
      "tagType": "X",
      "tagValue": "bar"
    }
  ]
}

response:

{
  "meta": {
    "error": {
      "message": "Schema for id 99 does not exist",
      "code": "TYPED_TAG_SCHEMA_NOT_FOUND",
      "uid": "kinja-core-ecac642a-5246-4060-9254-2c99eeed5eb0"
    },
    "warnings": []
  }
}

Saving tags for a post

POST api.kinja.com/api/core/typedtag/save

{
  "postId" : 200,
  "schemaId" : 100,
  "typedTags" : [
    {
      "tagType": "A",
      "tagValue": "foo"
    },
    {
      "tagType": "B",
      "tagValue": "bar"
    }
  ]
}

Getting tags for a post

GET api.kinja.com/api/core/typedtag/tags?postId=200

response:

{
  "meta": {
    "error": null,
    "warnings": []
  },
  "data": [
    {
      "tagType": "A",
      "tagValue": "foo"
    },
    {
      "tagType": "B",
      "tagValue": "bar"
    }
  ]
}

Getting posts for tag paths

GET api.kinja.com/api/core/typedtag/posts?schemaId=101&paths=series:gameofthrones

response:

{
  "meta": {
    "error": null,
    "warnings": []
  },
  "data": [
    300,
    305,
    309,
    312
  ]
}

GET api.kinja.com/api/core/typedtag/posts?schemaId=101&paths=series:gameofthrones|season:2

GET api.kinja.com/api/core/typedtag/posts?schemaId=101&paths=series:gameofthrones|season:2&paths=series:gameofthrones|season:3

GET api.kinja.com/api/core/typedtag/posts?schemaId=101&paths=series:gameofthrones&paths=series:breakingbad

GET api.kinja.com/api/core/typedtag/posts?schemaId=101&paths=series:gameofthrones|season:2&paths=series:breakingbad|season:4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment