Skip to main content

Hello,

I am working with custom_fields of a Service Request and I’m not able to create & populate a custom field with the API.

curl -v -u <APIKEY>:X -H "Content-Type: application/json" -X PUT -d '{"custom_fields":{"additional_property_1": "value1"}}' 'https://<SUBDOMAIN>.freshservice.com/api/v2/tickets/13336/requested_items/13336'

13336 is the ticket number

I am getting 
{"code":"access_denied","message":"You are not authorized to perform this action."}* Closing connection 0

Hi,

 

First are you using custom URL or the original freshservice URL? ( It’s only the original that works with API) 

The key you are using are admin or have at least access to the ticket? 

The request item ID is not the same as the one you have in the request portal. 
They get it’s own number. 

Can you use a GET to view the request ? 

 


Hello, Thank you for your reply.

I am using the original freshservice URL for the API requests.

The key I am using has admin rights.

I can use a GET to view the requested items. How do I get the request item ID? 

curl -u <APIKEY>:X -X GET https://<SUBDOMAIN>.freshservice.com/api/v2/tickets/13336/requested_items

 

I’ve tried something like 

curl -v -u <APIKEY>:X -H "Content-Type: application/json" -X PUT -d '{"custom_fields":{"additional_property_1": "value1"}}' 'https://<SUBDOMAIN>.freshservice.com/api/v2/tickets/13336/requested_items/25002328931'

then I get 
{"description":"Validation failed","errors":r{"field":"additional_property_1_133390","message":"Unexpected/invalid field in request","code":"invalid_field"}]}* Closing connection 0

I can’t seem to find the right combination.


Hello, Thank you for your reply.

I am using the original freshservice URL for the API requests.

The key I am using has admin rights.

I can use a GET to view the requested items. How do I get the request item ID? 

curl -u <APIKEY>:X -X GET https://<SUBDOMAIN>.freshservice.com/api/v2/tickets/13336/requested_items

 

I’ve tried something like 

curl -v -u <APIKEY>:X -H "Content-Type: application/json" -X PUT -d '{"custom_fields":{"additional_property_1": "value1"}}' 'https://<SUBDOMAIN>.freshservice.com/api/v2/tickets/13336/requested_items/25002328931'

then I get 
{"description":"Validation failed","errors":r{"field":"additional_property_1_133390","message":"Unexpected/invalid field in request","code":"invalid_field"}]}* Closing connection 0

I can’t seem to find the right combination.

When you do the GET you get all fields that service request has, you are using on of them? 


When you do the GET you get all fields that service request has, you are using on of them?

 

yes


➜  Repositories git:(main) ✗ curl -u <apiKey>:X -X GET https://<domain>.freshservice.com/api/v2/tickets/13336/requested_items
{"requested_items":m{"custom_fields":{"product_name":"e - prod","db_access":true,"databases":e"ALL"],"open_ssh_public_key":"ssh-rsa ... imported-openssh-key","environment":null,"production_access":null,"dev":null,"int":null,"cert":null,"foo":null,"fooint":null,"foocert":null,"vendor":false},"id":25002328931,"created_at":"2023-05-12T12:42:24Z","updated_at":"2023-05-12T12:42:24Z","quantity":1,"stage":1,"loaned":false,"cost_per_request":0.0,"remarks":null,"delivery_time":null,"is_parent":true,"service_item_id":162,"service_item_name":"HM - Database Access Request"}]}%
➜ Repositories git:(main) ✗ curl -v -u <apiKey:X -H "Content-Type: application/json" -X PUT -d '{"custom_fields":{"environment": "value1"}}' 'https://elsevierdev.freshservice.com/api/v2/tickets/13336/requested_items/25002328931'
* Trying 100.64.1.37:443...
* Connected to elsevierdev.freshservice.com (100.64.1.37) port 443 (#0)
...
* Connection #0 to host <domain>.freshservice.com left intact
{"description":"Validation failed","errors":e{"field":"environment_133390","message":"Unexpected/invalid field in request","code":"invalid_field"}]}%

I think I figured out the issue. It seems that if the value is null, you can’t update it. You also can’t create a new custom_field.


➜  Repositories git:(main) ✗ curl -u <apiKey>:X -X GET https://<domain>.freshservice.com/api/v2/tickets/13336/requested_items
{"requested_items":m{"custom_fields":{"product_name":"e - prod","db_access":true,"databases":e"ALL"],"open_ssh_public_key":"ssh-rsa ... imported-openssh-key","environment":null,"production_access":null,"dev":null,"int":null,"cert":null,"foo":null,"fooint":null,"foocert":null,"vendor":false},"id":25002328931,"created_at":"2023-05-12T12:42:24Z","updated_at":"2023-05-12T12:42:24Z","quantity":1,"stage":1,"loaned":false,"cost_per_request":0.0,"remarks":null,"delivery_time":null,"is_parent":true,"service_item_id":162,"service_item_name":"HM - Database Access Request"}]}%
➜ Repositories git:(main) ✗ curl -v -u <apiKey:X -H "Content-Type: application/json" -X PUT -d '{"custom_fields":{"environment": "value1"}}' 'https://elsevierdev.freshservice.com/api/v2/tickets/13336/requested_items/25002328931'
* Trying 100.64.1.37:443...
* Connected to elsevierdev.freshservice.com (100.64.1.37) port 443 (#0)
...
* Connection #0 to host <domain>.freshservice.com left intact
{"description":"Validation failed","errors":e{"field":"environment_133390","message":"Unexpected/invalid field in request","code":"invalid_field"}]}%

I think I figured out the issue. It seems that if the value is null, you can’t update it. You also can’t create a new custom_field.

Okay, strange getting that error. I use Postman for all my tests. 


So, if you use postman can you either create a new custom_field or update a null item with the API?


So, if you use postman can you either create a new custom_field or update a null item with the API?

I do it in general , I think it’s easier to test things. 

I should have read your question and not guessing. I can’t find any API endpoint to create new custom field for service items. 

I see that you have a field called environment and it is set to null. 
You like to update that field? What typ of field is it ? 
If you use this GET /api/v2/service_catalog/items/tdisplay_id] can you see the property on the environment field. 

Should work to update custom fields using API. 
 


I mean I read your question but skipped that you wanted to create a new field with API. 


Reply