# API request error 500

**URL:** <https://forum.inductiveautomation.com/t/api-request-error-500/107458>\
**Category:** Ignition\
**Tags:** ignition81, webdev\
**Created:** [June 17, 2025, 8:06am UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458 "2025-06-17T08:06:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![colle](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@colle](https://forum.inductiveautomation.com/u/colle)\
**Post date:** [June 17, 2025, 8:06am UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/1 "2025-06-17T08:06:10Z")

</div>

My JavaScript code belike  
try {  
const response = await fetch('saveManualDocs', {  
method: 'POST',  
headers: { 'Content-Type': 'application/json' },  
body: JSON.stringify({ docsdata: docs })  
});  
if (!response.ok) throw new Error('net work error');  
const result = await response.json();  
console.log('success:', result);  
} catch (error) {  
console.error('error:', error);  
}

My Handler belike this  
def doPost(request, session):

```
import json
try:
    # 获取并解析 JSON 请求体
    body = request['data']
    data = json.loads(body)
    
   
    if 'docsdata' in data and isinstance(data['docsdata'], dict) and data['docsdata']:
        
        return {'status': 200, 'message': '接收成功'}
    else:
        return {'status': 404, 'message': '缺少有效的 docsdata'}
except Exception as e:
    return {'status': 404, 'message': '请求处理失败: {}'.format(str(e))}

```

It looks like it should work correctly but it actually errors out and the browser reports 500,  
http://\*\*\*\*\*\*\*/system/webdev/resource\_center/UserManual/1742/saveManualDocs net::ERR\_ABORTED 500 ( Server Error)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2ff1cf61ae3a4b68b839e3b4fe640b9ec6f52a68.png)

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [June 17, 2025, 12:24pm UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/2 "2025-06-17T12:24:15Z")

</div>

If there is a 500 server error then the error should show up in the Gateway logs. Do you see anything in the logs when this happens?

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [June 17, 2025, 12:28pm UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/3 "2025-06-17T12:28:22Z")

</div>

Also, I would recommend putting your script in a script library function if you're going to import libraries (so that they are imported once on script restart rather than every time this runs). Even more so however, in this case, I would recommend using [system.util.jsonDecode()](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-jsonDecode). No need to import libraries.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [June 17, 2025, 1:55pm UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/4 "2025-06-17T13:55:02Z")

</div>

Can you doGet successfully?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/7/f7b590529cd0b59b757bee0779cbef0a2b18b3d8.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1a38a91b50874f3ec3e0c1b3b0c0a515964fec90.png)

---

<div class="post-metadata">

**Author:** ![Marcus\_Sysum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/marcus_sysum/32/57944_2.png) [@Marcus\_Sysum](https://forum.inductiveautomation.com/u/Marcus_Sysum)\
**Post date:** [June 17, 2025, 3:18pm UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/5 "2025-06-17T15:18:37Z")

</div>

> [@colle](#):
>
> ```python
> import json
> try:
> # 获取并解析 JSON 请求体
> body = request['data']
> data = json.loads(body)
>     
>    
> if 'docsdata' in data and isinstance(data['docsdata'], dict) and data['docsdata']:
>         
> return {'status': 200, 'message': '接收成功'}
> else:
> return {'status': 404, 'message': '缺少有效的 docsdata'}
> except Exception as e:
> return {'status': 404, 'message': '请求处理失败: {}'.format(str(e))}
> 
> ```

There are a couple things wrong with this script.  
The try/except statements is causing your errors to not surface. After removing this you will see errors on the gateway logs.  
the json loads is causing the first error. There is no need for this import. The request is already converted to a dictionary.  
Your return dictionary needs to have the content type.  
This script below does not fix the exception error if one arises. But should get you going in the right direction.

```python
try:
    # 获取并解析 JSON 请求体
		body = request['data']
		#data = json.loads(body)
	
		if 'docsdata' in body and isinstance(body['docsdata'], dict) and body['docsdata']: 	
			return {'json':{'status': 200, 'message': u'接收成功'}}
		else:
			return {'json':{'status': 404, 'message': u'缺少有效的 docsdata'}}
	except Exception as e:
		return {'json':{'status': 404, 'message': u'请求处理失败: {}'.format(str(e))}}

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 17, 2025, 4:55pm UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/6 "2025-06-17T16:55:07Z")

</div>

Marcus didn't call it out but you also **must** prefix all string literals in Ignition (which is just Python 2) with `u` if they contain non-ASCII characters:  
`'message': u'接收成功'}`  
**not**  
`'message': '接收成功'}`

---

<div class="post-metadata">

**Author:** ![colle](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@colle](https://forum.inductiveautomation.com/u/colle)\
**Post date:** [June 19, 2025, 3:03am UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/7 "2025-06-19T03:03:48Z")

</div>

The fact that I don't have access to the logs due to my company's authority causes me to not be able to correctly get the actual statement that went wrong

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 19, 2025, 11:52am UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/8 "2025-06-19T11:52:36Z")

</div>

> [@colle](#):
>
> I don't have access to the logs

This will utterly cripple your ability to develop in Ignition. Do they understand that?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 19, 2025, 12:09pm UTC](https://forum.inductiveautomation.com/t/api-request-error-500/107458/9 "2025-06-19T12:09:15Z")

</div>

You do not need to RDP into the machine to see the logs, just login to the status page of the gateway which you can access via the IP or hostname in a browser. Then go to Status-\>Logs.
