Search Storyblok's Documentation
  1. Create a Datasource

Create a Datasource

This endpoint allows you to create a new datasource.

https://mapi.storyblok.com/v1/spaces/:space_id/datasources

Path Parameters

  • :space_id

    required number

    Numeric ID of a space

Request Body Properties

  • datasource

    The Datasource Object

    Your full datasource object

    • name

      required string

      The complete name provided for a datasource

    • slug

      required string

      Slug of a datasource

Response Properties

  • datasource

    The Datasource Object
    • id

      number

      The numeric ID of the datasource

    • name

      string

      The complete name provided for a datasource

    • slug

      string

      Slug of a datasource

    • dimensions

      object[]

      An array listing the dimensions (e.g., per country, region, language, or other context) defined for the datasource. While creating or updating dimensions inside datasources, a different key - dimensions_attributes should be used instead with name and entry_value .

      • id

        number

        The numeric ID

      • name

        string

        The complete name provided for the datasource

      • entry_value

        string

        The value provided for the datasource dimension (e.g., a language code)

      • datasource_id

        number

        The numeric ID of the datasource that the dimension belongs to

      • created_at

        string

        Creation date (Format: yyyy-MM-dd'T'HH:mm:ssZ)

      • updated_at

        string

        Latest update date (Format: yyyy-MM-dd'T'HH:mm:ssZ)

    • created_at

      string

      Creation date (Format: yyyy-MM-dd'T'HH:mm:ssZ)

    • updated_at

      string

      Latest update date (Format: yyyy-MM-dd'T'HH:mm:ssZ)

Example Request

Request
curl "https://mapi.storyblok.com/v1/spaces/606/datasources/" \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_OAUTH_TOKEN" \
  -d "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"labels\"}}"
Request
// Using the Universal JavaScript Client:
// https://github.com/storyblok/storyblok-js-client
Storyblok.post('/spaces/606/datasources/', {
  "datasource": {
    "name": "Labels for Website",
    "slug": "labels"
  }
})
  .then(response => {
    console.log(response)
  }).catch(error => { 
    console.log(error)
  })
Request
$client = new \Storyblok\ManagementClient('YOUR_OAUTH_TOKEN');

$payload = [
  "datasource" =>  [
    "name" =>  "Labels for Website",
    "slug" =>  "labels"
  ]
];

$client->post('/spaces/606/datasources/', $payload)->getBody();
Request
require 'storyblok'
client = Storyblok::Client.new(oauth_token: 'YOUR_OAUTH_TOKEN')

payload = {
  "datasource" =>  {
    "name" =>  "Labels for Website",
    "slug" =>  "labels"
  }
}

client.post('/spaces/606/datasources/', payload)
Request
HttpResponse<String> response = Unirest.post("https://mapi.storyblok.com/v1/spaces/606/datasources/")
  .header("Content-Type", "application/json")
  .header("Authorization", "YOUR_OAUTH_TOKEN")
  .body("{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"labels\"}}")
  .asString();
Request
var client = new RestClient("https://mapi.storyblok.com/v1/spaces/606/datasources/");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "YOUR_OAUTH_TOKEN");
request.AddParameter("application/json", "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"labels\"}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Request
import Foundation

let headers = [
  "Content-Type": "application/json",
  "Authorization": "YOUR_OAUTH_TOKEN"
]

let postData = NSData(data: "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"labels\"}}".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "https://mapi.storyblok.com/v1/spaces/606/datasources/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)

request.method = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
Request
import requests

url = "https://mapi.storyblok.com/v1/spaces/606/datasources/"

querystring = {}

payload = "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"labels\"}}"
headers = {
  'Content-Type': "application/json",
  'Authorization': "YOUR_OAUTH_TOKEN"
}

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

Example for adding dimensions while creating a datasource -

To add dimensions, use the dimensions_attributes key.


Request
curl "https://mapi.storyblok.com/v1/spaces/606/datasources/" \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: YOUR_OAUTH_TOKEN" \
  -d "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"label\",\"dimensions_attributes\": [{\"name\": \"Spanish\",\"entry_value\": \"es\"},{\"name\": \"Germaannn\",\"entry_value\" : \"something\"}]}}"
Request
// Using the Universal JavaScript Client:
// https://github.com/storyblok/storyblok-js-client
Storyblok.post('/spaces/606/datasources/', {
  "datasource": {
    "name": "Labels for Website",
    "slug": "label",
    "dimensions_attributes": [
        {
            "name": "Spanish",
            "entry_value": "es"      
        },
        {
            "name": "Germaannn",
            "entry_value" : "something"
        }
    ]
  }
})
  .then(response => {
    console.log(response)
  }).catch(error => { 
    console.log(error)
  })
Request
$client = new \Storyblok\ManagementClient('YOUR_OAUTH_TOKEN');

$payload = [
  "datasource" =>  [
    "name" =>  "Labels for Website",
    "slug" =>  "label",
    "dimensions_attributes" =>  [
        [
            "name" =>  "Spanish",
            "entry_value" =>  "es"      
        ],
        [
            "name" =>  "Germaannn",
            "entry_value"  =>  "something"
        ]
    ]
  ]
];

$client->post('/spaces/606/datasources/', $payload)->getBody();
Request
require 'storyblok'
client = Storyblok::Client.new(oauth_token: 'YOUR_OAUTH_TOKEN')

payload = {
  "datasource" =>  {
    "name" =>  "Labels for Website",
    "slug" =>  "label",
    "dimensions_attributes" =>  [
        {
            "name" =>  "Spanish",
            "entry_value" =>  "es"      
        },
        {
            "name" =>  "Germaannn",
            "entry_value"  =>  "something"
        }
    ]
  }
}

client.post('/spaces/606/datasources/', payload)
Request
HttpResponse<String> response = Unirest.post("https://mapi.storyblok.com/v1/spaces/606/datasources/")
  .header("Content-Type", "application/json")
  .header("Authorization", "YOUR_OAUTH_TOKEN")
  .body("{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"label\",\"dimensions_attributes\": [{\"name\": \"Spanish\",\"entry_value\": \"es\"},{\"name\": \"Germaannn\",\"entry_value\" : \"something\"}]}}")
  .asString();
Request
var client = new RestClient("https://mapi.storyblok.com/v1/spaces/606/datasources/");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "YOUR_OAUTH_TOKEN");
request.AddParameter("application/json", "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"label\",\"dimensions_attributes\": [{\"name\": \"Spanish\",\"entry_value\": \"es\"},{\"name\": \"Germaannn\",\"entry_value\" : \"something\"}]}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Request
import Foundation

let headers = [
  "Content-Type": "application/json",
  "Authorization": "YOUR_OAUTH_TOKEN"
]

let postData = NSData(data: "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"label\",\"dimensions_attributes\": [{\"name\": \"Spanish\",\"entry_value\": \"es\"},{\"name\": \"Germaannn\",\"entry_value\" : \"something\"}]}}".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "https://mapi.storyblok.com/v1/spaces/606/datasources/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)

request.method = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
Request
import requests

url = "https://mapi.storyblok.com/v1/spaces/606/datasources/"

querystring = {}

payload = "{\"datasource\": {\"name\": \"Labels for Website\",\"slug\": \"label\",\"dimensions_attributes\": [{\"name\": \"Spanish\",\"entry_value\": \"es\"},{\"name\": \"Germaannn\",\"entry_value\" : \"something\"}]}}"
headers = {
  'Content-Type': "application/json",
  'Authorization': "YOUR_OAUTH_TOKEN"
}

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)