0

I'm trying to create a template map following this tutorial from the cartoDB's maps API.

My template.json file

{
  version: "0.0.1",
  name: "template_1",
  // embedded authorization certificate 
  auth: {
   method: "open" 
  },
  placeholders: {
      color: {
        type:"css_color",
        default:"blue"
      },
      del_s: {
        type:"sql_literal",
        default: "19420210"
      },
      del_n: {
        type:"number",
        default: 19420210
      }
  },
  layergroup: {
    "version": "1.0.1",
    "layers": [{
      "type": "cartodb",
      "options": {
        "cartocss_version": "2.1.1", 
        "cartocss": "#layer { polygon-fill: <%= color %>; }",
        "sql": "select * from table1 WHERE del = <%= del_s %>",
        "interactivity": ["cartodb_id","del","gk"]
      }
    },
    {
      "type": "cartodb",
      "options": {
        "cartocss_version": "2.1.1", 
        "cartocss": "#layer { polygon-fill: red; }",
        "sql": "SELECT * from table2 WHERE del = <%= del_n %>",
        "interactivity": [ "cartodb_id","del"] 
      }
    }]
  } 
}

When I try to make the request to create the template..

curl -X POST \
   -H 'Content-Type: application/json' \
   -d @template.json \
   'https://docs.cartodb.com/api/v1/map/named?api_key=568kaka8bc89'

I can not connect, I get an error:

curl: (7) Failed connect to docs.cartodb.com:443; Connection timed out

anyone knows what I'm doing wrong?

UPDATE

Try with my username, and get an "internal server error"

curl -X POST \
   -H 'Content-Type: application/json' \
   -d @template.json \
   'https://myusername.cartodb.com/api/v1/map/named?api_key=myapikey'
1

I finally managed to create the template, think it's a bug either the documentation or behaviour. It seems that you need to use quotation marks around the fields and can't use comments in the code

like this:

{ "version": "0.0.1", "name": "template_io", "auth": {"method": "open" }..
  • Yes, it's a bug in the documentation, we are fixing, sorry about that – javisantana Sep 3 '14 at 10:28
0

in the curl you need to use your username instead of docs, like

curl -X POST \
   -H 'Content-Type: application/json' \
   -d @template.json \
   'https://USERNAME.cartodb.com/api/v1/map/named?api_key=YOUR_API_KEY'

We use docs as a placeholder, so replace USERNAME and YOUR_API_KEY with your cartodb username and api key

  • thanks Javi, I have already tried, with my username it give me an 'internal server error' – sigon Sep 2 '14 at 9:27
  • when I try the curl -X GET 'username.cartodb.com/tiles/template?api_key=mykey' the response is: {"template_ids":["username@tpl_9342e510_31db_11e4_9581_0e7333fa50","username@tpl_a9d222b0_3054_11e4_a4ec_230854a1cb","username@tpl_b188bba_31fd_11e4_8c9a_0edb5057"]} – sigon Sep 2 '14 at 10:10
  • when I use the -X GET command listed above, I got a list of the visualizations I made in the cartodb UI, I am not able to create a template map with a post resquest: got 'internal server error' – sigon Sep 2 '14 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.