API for creating solid pods

This sounds like your authorizationValue is not properly set.

Here’s the complete script that created https://secure.agefix.space/testomate/

You can save it as someScript.js locally and execute with node someScript.js

// baseUrl = 'http://localhost:3000'
baseUrl = 'https://secure.agefix.space'
indexUrl = baseUrl + '/.account/'

async function main() {
// get available endpoints
res = await fetch(indexUrl)
data = await res.json()
controls = data.controls

// create an account (requires no parameters)
res = await fetch(controls.account.create, { method: 'POST' }) 
data = await res.json()
authorizationValue = data.authorization

// get available endpoints, but now for the fresh account (should also work via the cookie, authorization header is probably not necessary)
res = await fetch(indexUrl, { headers: { authorization: `CSS-Account-Token ${authorizationValue}` } })
data = await res.json()
controls = data.controls

// setup a login via email+password for the current account
res = await fetch(controls.password.create, {
  headers: {
    authorization: `CSS-Account-Token ${authorizationValue}`,
    'content-type': 'application/json'
  },
  method: 'POST',
  body: JSON.stringify({
    email: 'test@example.org',
    password: 'secret-12345',
  }),
})
data = await res.json()


// now we can login with email+password
res = await fetch(controls.password.login, {
  headers: {
    'content-type': 'application/json'
  },
  method: 'POST',
  body: JSON.stringify({
    email: 'test@example.org',
    password: 'secret-12345',
  }),
})
data = await res.json()
authorizationValue = data.authorization

// get available endpoints for current account
res = await fetch(indexUrl, { headers: { authorization: `CSS-Account-Token ${authorizationValue}` } })
data = await res.json()
controls = data.controls
console.log(controls.account.pod)


// setup a pod
res = await fetch(controls.account.pod, {
  headers: {
    authorization: `CSS-Account-Token ${authorizationValue}`,
    'content-type': 'application/json'
  },
  method: 'POST',
  body: JSON.stringify({
    name: 'testomate',
  }),
})
data = await res.json()

console.log(`Created pod: ${JSON.stringify(data, undefined, 2)}`)
}

main()
1 Like