REST API Explorer - Insert Multiple Records

Andr_1
Tera Contributor

Hello,

I am testing the "Insert Multiple Records from the same request (POST)" API with the Rest API Explorer module.

I sent on the request body the follow JSON with this "records" format:

 

{
   "records":[
      {
         "u_work_phone":"test4545"
      },
      {
         "u_work_phone":"test123"
      }
   ]
}

 

 When I send.. it creates 2 records on my staging table. So far so good.

My question is: Can I change this request body format to something like this?

 

{
	"FOBusinessUnit": {
		"businessUnit": [
			{
				"u_work_phone":"test4545"
			},
			{
				"u_work_phone":"test"
			}
		]
	}
}

 

 

 If I send the JSON like above, it gives me this error message:

{
  "error": {
    "message": "Invalid JSON Object",
    "detail": "There is no root array element with name records"
  },
  "status": "failure"
}


Thank you

André Ramos

 

1 ACCEPTED SOLUTION

Aylee Andersen
Kilo Sage

Hi @Andr_1,

 

According to the API documentation, it needs to live within the "results" array, just like you have it in your first code snippet. You can't send custom JSON or else the API won't know how to parse it. That being said, is there a specific goal you are trying to accomplish by wrapping it in an "FOBusinessUnit" object and "businessUnit" array? Perhaps there is another way to accomplish the same goal without modifying the request body's JSON structure?

 

- Aylee 

View solution in original post

1 REPLY 1

Aylee Andersen
Kilo Sage

Hi @Andr_1,

 

According to the API documentation, it needs to live within the "results" array, just like you have it in your first code snippet. You can't send custom JSON or else the API won't know how to parse it. That being said, is there a specific goal you are trying to accomplish by wrapping it in an "FOBusinessUnit" object and "businessUnit" array? Perhaps there is another way to accomplish the same goal without modifying the request body's JSON structure?

 

- Aylee