Creating a new resource with transifex_api.Resource.create

Hi,

I’m trying to create a new resource like this:

transifex_api.Resource.create(project=project, name="test", slug="test", i18n_format="PO")

I’m struggling to figure out what should be the i18n_format param. If I don’t provide it I get

JsonApiException_400_invalid: (400, [{‘status’: ‘400’, ‘code’: ‘invalid’, ‘title’: ‘Field i18n_format is invalid’, ‘detail’: “‘i18n_format’ is a required property”, ‘source’: {‘pointer’: ‘/data/relationships/i18n_format’}}], <Response [400]>)

When provided I get

JsonApiException_400_invalid: (400, [{‘status’: ‘400’, ‘code’: ‘invalid’, ‘title’: ‘Field attributes is invalid’, ‘detail’: “Additional properties are not allowed (‘i18n_format’ was unexpected)”, ‘source’: {‘pointer’: ‘/data/attributes’}}, {‘status’: ‘400’, ‘code’: ‘invalid’, ‘title’: ‘Field i18n_format is invalid’, ‘detail’: “‘i18n_format’ is a required property”, ‘source’: {‘pointer’: ‘/data/relationships/i18n_format’}}], <Response [400]>)

What’s the correct method of creating it?

Hi Robert,

In the create new resource endpoint, i18n_format is an object that contains another object called data. Inside the data object, there should be two key-value objects: Type and id. The type value should be “i18n_formats”, and the id value should be the i18n file format code, which in your case is PO. Your payload should be something like the following:

{
  "data": {
    "type": "resources",
    "attributes": {
      "slug": "test",
      "name": "test"
    },
    "relationships": {
      "project": {
        "data": {
          "type": "projects",
          "id": "o:your_organization_slug:p:your_project_slug"
        }
      },
      "i18n_format": {
        "data": {
          "type": "i18n_formats",
          "id": "PO"
        }
      }
    }
  }
}

Let me know if the above info helps you solve your situation,

Regards,

Sandy