Community
Showing results for 
Search instead for 
Do you mean 
Reply

How to pass in a guid to a post api?

Accepted Solution Solved
New Member
Posts: 5
Country: Australia
Accepted Solution

How to pass in a guid to a post api?

If I pass in the json { "name": "some name", "id": "5d96b723-792d-4dce-b2af-518628644eef" } to {url}/api/Companies with the correct headers I get a 400 bad request response.

 

If I pass in the json without the id { "name": "some name" } to {url}/api/Companies with the correct headers I get a 201 created response with json with a new id in the response.

 

I get the same results if I use a x-www-form-urlencoded. Works without the id. Fails with the id.

 

The full code checks if there is an id in the database, then checks if there is a matching name, then attempts to post if no matches are found.

 

Assuming id is not present in the database what is the correct way to pass in a GUID so that I'd get a 201 for the first call ?  


Accepted Solutions
Solution
Accepted by topic author csmu
‎05-16-2017 07:59 PM
Administrator
Posts: 4,024
Country: United_Kingdom

Re: How to pass in a guid to a post api?

Hi csmu,

 

The API does not accept guid's in POST requests to create new Companies. The guid for the created record is assigned by the API and provided in the response. 

 

Deleting the id or, passing a nulled id will allow the request to work.

 

For example:

THIS WORKS:
{
	“id”: “00000000-0000-0000-0000-000000000000”,
	…
}

OR

{
	"name": "test",
	…
}


THIS FAILS:
{
	"id": "4F28AED1-8836-4857-B527-69979D7B1B32",
	…
}

View solution in original post


All Replies
Solution
Accepted by topic author csmu
‎05-16-2017 07:59 PM
Administrator
Posts: 4,024
Country: United_Kingdom

Re: How to pass in a guid to a post api?

Hi csmu,

 

The API does not accept guid's in POST requests to create new Companies. The guid for the created record is assigned by the API and provided in the response. 

 

Deleting the id or, passing a nulled id will allow the request to work.

 

For example:

THIS WORKS:
{
	“id”: “00000000-0000-0000-0000-000000000000”,
	…
}

OR

{
	"name": "test",
	…
}


THIS FAILS:
{
	"id": "4F28AED1-8836-4857-B527-69979D7B1B32",
	…
}
New Member
Posts: 5
Country: Australia

Re: How to pass in a guid to a post api?

Thanks Gary

 

Cheers.

 

Keith.