careful-honey-27437
05/25/2025, 7:37 PMbrief-egg-61061
05/25/2025, 7:37 PMbrief-egg-61061
05/25/2025, 7:37 PMjs import { RelationshipApi, Configuration } from "@ory/client-fetch" const ory = new RelationshipApi( new Configuration({ basePath: "https://<your-project-slug>.<http://projects.oryapis.com|projects.oryapis.com>", // or your tunnel/custom domain URL accessToken: "<your-ory-access-token>", // Use a valid Ory PAT or token }) ) const createRelationshipBody = { namespace: "Group", object: "developer", relation: "members", subject: "User:Patrik" } ory.createRelationship({ createRelationshipBody }) .then(response => { console.log("Relationship created:", response.data) }) .catch(error => { console.error("Error creating relationship:", error) })
Key points: - Use the relationship.createRelationship method, not the deprecated write.createRelationTuple. - Provide your Ory Network project’s basePath and a valid access token for authentication. - The body should specify the namespace, object, relation, and subject as per your permission model. This pattern is confirmed in the official Ory SDK v1 upgrade guide and aligns with the current API structure for Ory Network tenants [SDK V1 upgrade guide](https://www.ory.sh/docs/guides/upgrade/sdk-v1#permissions--access-control). For more details on relationship concepts and API authentication, see the Ory documentation on [relationships](https://www.ory.sh/docs/keto/concepts/relation-tuples) and [API reference](https://www.ory.sh/docs/reference/api).careful-honey-27437
05/25/2025, 9:25 PMbrief-egg-61061
05/25/2025, 9:25 PMbrief-egg-61061
05/25/2025, 9:26 PMcreateRelationship
method of the Ory Permissions API. The request body must include at least namespace
, object
, and relation
, and either subject_id
or a subject_set
object. 2. Request Body Example: json { "namespace": "example_namespace", "object": "example_object", "relation": "example_relation", "subject_id": "example_subject" }
Or, for a subject set: json { "namespace": "example_namespace", "object": "example_object", "relation": "example_relation", "subject_set": { "namespace": "subject_namespace", "object": "subject_object", "relation": "subject_relation" } }
3. Response: - On success: HTTP 201 with the created relationship object. - On error: Standard Ory JSON API error format with details in the error
property. 4. Error Handling: If you receive a response like: json { "response": {}, "name": "ResponseError" }
This typically means the API returned an error response (possibly with an empty body), and the client library wrapped it in a ResponseError
. Check your request body for required fields and ensure your access token and base path are correct. References: - [Ory API Reference – createRelationship](https://www.ory.sh/docs/reference/api) - [Keto API Reference – createRelationship](https://www.ory.sh/docs/keto/reference/rest-api) Summary: - Ensure your request body includes all required fields. - Use a valid access token and correct base path for your Ory Network project. - Handle errors by inspecting the ResponseError
and checking for missing or invalid fields in your request. If you need a specific code example, the knowledge sources do not provide one, but the above structure and error handling are directly derived from the official API documentation. If you need further troubleshooting, please provide the exact request payload and configuration you are using.careful-honey-27437
05/25/2025, 9:29 PM[Ory Keto] Created: ${tuple.namespace} ${tuple.object} ${tuple.relation} ${tuple.subject_id}
)
} catch (err) {
console.log(JSON.stringify(err, null, 3))
log(“[Ory Keto] Error creating relationship: ” + err)
throw new Error([Ory Keto] Failed to create sysadmin relationship
)
}
}careful-honey-27437
05/25/2025, 9:29 PM[Ory Keto] Created: ${tuple.namespace} ${tuple.object} ${tuple.relation} ${tuple.subject_id}
)
} catch (err) {
console.log(JSON.stringify(err, null, 3))
log(“[Ory Keto] Error creating relationship: ” + err)
throw new Error([Ory Keto] Failed to create sysadmin relationship
)
}
}brief-egg-61061
05/25/2025, 9:29 PMbrief-egg-61061
05/25/2025, 9:29 PMcreateRelationship
must include at least namespace
, object
, and relation
, and either subject_id
or subject_set
. The property should be named exactly as required by the API (subject_id
, not subjectId
or subject
). Double-check that your createRelationshipBody
matches this structure: json { "namespace": "example_namespace", "object": "example_object", "relation": "example_relation", "subject_id": "example_subject" }
or, for a subject set: json { "namespace": "example_namespace", "object": "example_object", "relation": "example_relation", "subject_set": { "namespace": "subject_namespace", "object": "subject_object", "relation": "subject_relation" } }
[Keto API Reference – createRelationship](https://www.ory.sh/docs/keto/reference/rest-api) 2. Error Handling: The error you posted: json { "response": {}, "name": "ResponseError" }
suggests that the API call failed, but the response body was empty. This often happens if the request is malformed or required fields are missing. The Ory API returns detailed error messages in the error
property of the response, but if the body is empty, it may indicate a client-side or network issue, or a misconfiguration in the request. 3. Access Token and Base Path: Ensure you are passing a valid Ory Network access token and the correct base path for your project, as required for authentication [Ory API Reference – Authentication](https://www.ory.sh/docs/reference/api). 4. Function Parameter: Your function signature includes subject
, but you are not using it. Make sure you are passing the correct createRelationshipBody
and that it contains the required fields. 5. Logging: The commented-out log line references tuple
, which is not defined in your function. If you want to log the created relationship, you should capture the response from createRelationship
and log its properties. Example Correction: js async function createKetoRelationshipForSubject(createRelationshipBody) { try { const response = await keto.createRelationship({ createRelationshipBody }) // If you want to log the created relationship: // const tuple = response.data // log(`[Ory Keto] Created: ${tuple.namespace} ${tuple.object} ${tuple.relation} ${tuple.subject_id}`) } catch (err) { console.log(JSON.stringify(err, null, 3)) log("[Ory Keto] Error creating relationship: " + err) throw new Error("[Ory Keto] Failed to create sysadmin relationship") } }
Summary: - Double-check the structure and field names in your createRelationshipBody
. - Ensure authentication and base path are correct. - Capture and log the response for better debugging. - If the error persists and the response is empty, verify network connectivity and that your API client is up to date. If you need more specific troubleshooting, please provide the actual createRelationshipBody
you are sending and details about your keto
client configuration. The knowledge sources do not provide further details on Node.js error handling or SDK-specific quirks beyond the API contract and error format.