[[rest-api-refer-to-items-created-earlier-in-the-same-batch-job]]
=== Refer to items created earlier in the same batch job ===

The batch operation API allows you to refer to the URI returned from a
created resource in subsequent job descriptions, within the same batch
call.

Use the +{[JOB ID]}+ special syntax to inject URIs from created resources
into JSON strings in subsequent job descriptions.


.Final Graph
["dot", "Final-Graph-Refer-to-items-created-earlier-in-the-same-batch-job.svg", "neoviz"]
----
  N80 [
    label = "{Node\[80\]|name = \'bob\'\l}"
  ]
  N80 -> N81 [
    color = "#2e3436"
    fontcolor = "#2e3436"
    label = "KNOWS\nsince = \'2010\'\l"
  ]
  N81 [
    label = "{Node\[81\]|age = 12\l}"
  ]
----

_Example request_

* *+POST+*  +http://localhost:7474/db/data/batch+
* *+Accept:+* +application/json+
* *+Content-Type:+* +application/json+
[source,javascript]
----
[ {
  "method" : "POST",
  "to" : "/node",
  "id" : 0,
  "body" : {
    "name" : "bob"
  }
}, {
  "method" : "POST",
  "to" : "/node",
  "id" : 1,
  "body" : {
    "age" : 12
  }
}, {
  "method" : "POST",
  "to" : "{0}/relationships",
  "id" : 3,
  "body" : {
    "to" : "{1}",
    "data" : {
      "since" : "2010"
    },
    "type" : "KNOWS"
  }
}, {
  "method" : "POST",
  "to" : "/index/relationship/my_rels",
  "id" : 4,
  "body" : {
    "key" : "since",
    "value" : "2010",
    "uri" : "{3}"
  }
} ]
----


_Example response_

* *+200:+* +OK+
* *+Content-Type:+* +application/json+
[source,javascript]
----
[ {
  "id" : 0,
  "location" : "http://localhost:7474/db/data/node/80",
  "body" : {
    "outgoing_relationships" : "http://localhost:7474/db/data/node/80/relationships/out",
    "data" : {
      "name" : "bob"
    },
    "traverse" : "http://localhost:7474/db/data/node/80/traverse/{returnType}",
    "all_typed_relationships" : "http://localhost:7474/db/data/node/80/relationships/all/{-list|&|types}",
    "property" : "http://localhost:7474/db/data/node/80/properties/{key}",
    "self" : "http://localhost:7474/db/data/node/80",
    "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/80/relationships/out/{-list|&|types}",
    "properties" : "http://localhost:7474/db/data/node/80/properties",
    "incoming_relationships" : "http://localhost:7474/db/data/node/80/relationships/in",
    "extensions" : {
    },
    "create_relationship" : "http://localhost:7474/db/data/node/80/relationships",
    "paged_traverse" : "http://localhost:7474/db/data/node/80/paged/traverse/{returnType}{?pageSize,leaseTime}",
    "all_relationships" : "http://localhost:7474/db/data/node/80/relationships/all",
    "incoming_typed_relationships" : "http://localhost:7474/db/data/node/80/relationships/in/{-list|&|types}"
  },
  "from" : "/node"
}, {
  "id" : 1,
  "location" : "http://localhost:7474/db/data/node/81",
  "body" : {
    "outgoing_relationships" : "http://localhost:7474/db/data/node/81/relationships/out",
    "data" : {
      "age" : 12
    },
    "traverse" : "http://localhost:7474/db/data/node/81/traverse/{returnType}",
    "all_typed_relationships" : "http://localhost:7474/db/data/node/81/relationships/all/{-list|&|types}",
    "property" : "http://localhost:7474/db/data/node/81/properties/{key}",
    "self" : "http://localhost:7474/db/data/node/81",
    "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/81/relationships/out/{-list|&|types}",
    "properties" : "http://localhost:7474/db/data/node/81/properties",
    "incoming_relationships" : "http://localhost:7474/db/data/node/81/relationships/in",
    "extensions" : {
    },
    "create_relationship" : "http://localhost:7474/db/data/node/81/relationships",
    "paged_traverse" : "http://localhost:7474/db/data/node/81/paged/traverse/{returnType}{?pageSize,leaseTime}",
    "all_relationships" : "http://localhost:7474/db/data/node/81/relationships/all",
    "incoming_typed_relationships" : "http://localhost:7474/db/data/node/81/relationships/in/{-list|&|types}"
  },
  "from" : "/node"
}, {
  "id" : 3,
  "location" : "http://localhost:7474/db/data/relationship/26",
  "body" : {
    "start" : "http://localhost:7474/db/data/node/80",
    "data" : {
      "since" : "2010"
    },
    "self" : "http://localhost:7474/db/data/relationship/26",
    "property" : "http://localhost:7474/db/data/relationship/26/properties/{key}",
    "properties" : "http://localhost:7474/db/data/relationship/26/properties",
    "type" : "KNOWS",
    "extensions" : {
    },
    "end" : "http://localhost:7474/db/data/node/81"
  },
  "from" : "http://localhost:7474/db/data/node/80/relationships"
}, {
  "id" : 4,
  "location" : "http://localhost:7474/db/data/index/relationship/my_rels/since/2010/26",
  "body" : {
    "indexed" : "http://localhost:7474/db/data/index/relationship/my_rels/since/2010/26",
    "start" : "http://localhost:7474/db/data/node/80",
    "data" : {
      "since" : "2010"
    },
    "self" : "http://localhost:7474/db/data/relationship/26",
    "property" : "http://localhost:7474/db/data/relationship/26/properties/{key}",
    "properties" : "http://localhost:7474/db/data/relationship/26/properties",
    "type" : "KNOWS",
    "extensions" : {
    },
    "end" : "http://localhost:7474/db/data/node/81"
  },
  "from" : "/index/relationship/my_rels"
} ]
----


