API - Create Service Request

  • 10 June 2020
  • 2 replies
  • 396 views

Userlevel 3
Badge +9

Does anyone have an example of how to create a service request via the API.  I keep getting errors and need a good place to start.



2 replies

Userlevel 1

Hi Patrick,


Could you please let us know the errors you are running into while creating the Service Request with API?


Also, here’s how you can start with the basic code for Creating a Service Request using APIs.


Callback URL : https://domain.freshservice.com/api/v2/service_catalog/items/1/place_request


1” Refers to the Item ID. You can find the Item ID by navigating to any item under Admin → Service Catalog and check its URL.



Request :

{
"email": "someone@example.com"
}



If you would like to use the same in a cURL format :

curl -v -u user@yourcompany.com:test -H "Content-Type: application/json" -d '{"email": "someone@example.com" }' -X POST 'https://domain.freshservice.com/api/v2/service_catalog/items/1/place_request'


Likewise, if you would like to create a Service Request with Custom Fields Along with Child Items with its custom fields, you can find the API commands as given below:

Callback URL : https://domain.freshservice.com/api/v2/service_catalog/items/1/place_request

Again, 1 here refers to the Item ID.


Request :

{
"email": "someone@example.com",
"custom_fields": {
"parent_custom_field": "test"
},
"child_items": [
{
"service_item_id": 2,
"custom_fields": {
"child_custom_field": "test"
}
}
]
}


Here 2 also refers to the item ID and parent_custom_field and child_custom_field are the payloads for the custom of fields of Parent and Child Tickets respectively.


curl -v -u user@yourcompany.com:test -H "Content-Type: application/json" -d '{ "email": "someone@example.com", "custom_fields": { "parent_custom_field": "test" }, "child_items": [ { "service_item_id": 2, "custom_fields": { "child_custom_field": "test" } } ] }' -X POST 'https://domain.freshservice.com/api/v2/service_catalog/items/1/place_request'


Do let us know in case of any further assistance 🙂

Thanks,
Pranav B

Badge

Hi Pranav, In custom fields when you have a field which accepts user id, how do you pass it in this API because  the user id is of 64 bit integer  in FS and json only supports 32 bit. String cannot be passed as user id can only be integer. Thanks in advance!

Reply