Created
December 24, 2025 11:12
-
-
Save laurentpellegrino/8c9ad39a92909c5759a66fd5b196e6a9 to your computer and use it in GitHub Desktop.
Example to create a Noticeable Publication with segments using Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require "json" | |
| require "net/http" | |
| require "uri" | |
| endpoint = ENV.fetch("NOTICEABLE_GRAPHQL_ENDPOINT", "https://api.noticeable.io/graphql") | |
| api_key = ENV.fetch("NOTICEABLE_API_KEY") | |
| project_id = ENV.fetch("NOTICEABLE_PROJECT_ID") | |
| mutation = <<~GRAPHQL | |
| mutation { | |
| createPublication( | |
| input: { | |
| projectId: "#{project_id}" | |
| author: { fullName: "John Doe" } | |
| title: "Publication from Docker Ruby" | |
| content: "Hello **Markdown**" | |
| isDraft: false | |
| publishedAt: "#{Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')}" | |
| segments: ["User:X"] | |
| labels: [{ slug: "new" }] | |
| isArchived: true | |
| } | |
| ) { | |
| publication { | |
| id | |
| permalink | |
| } | |
| } | |
| } | |
| GRAPHQL | |
| uri = URI.parse(endpoint) | |
| http = Net::HTTP.new(uri.host, uri.port) | |
| http.use_ssl = (uri.scheme == "https") | |
| req = Net::HTTP::Post.new(uri.request_uri) | |
| req["Content-Type"] = "application/json" | |
| req["Authorization"] = "Apikey #{api_key}" | |
| req.body = { query: mutation }.to_json | |
| res = http.request(req) | |
| puts JSON.pretty_generate((JSON.parse(res.body) rescue { raw: res.body })) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://graphdoc.noticeable.io/createpublicationinput.doc