function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bryan Leaman 6Bryan Leaman 6 

How can I collect a debug log for an incoming API call?

We have a third-party integration with our salesforce org. I believe they're using SOAP api calls at API version 41.0.  The calls are creating data in our org and those record inserts and updates fire custom triggers. However, when I add a user trace for the API user, I don't get any logs of the activity. 

I haven't coded SOAP apis into salesforce, but I see there are debug headers that are available. But I don't want debugging turned on for every call, just when I initiate a trace on the user.  

Would adding debug headers to the API calls *always* generate logs? Or would it only generate logs when I define a user trace for the API user?
Best Answer chosen by Bryan Leaman 6
Bryan Leaman 6Bryan Leaman 6
These are inbound only, and yes, when I add a trace on the API user from Setup | Debug Logs, no log files are generated. However, I found that if I login as the API user and launch Developer Console, then I *do* see log files being generated that are not visible from Setup | Debug Logs. However, it's been hit & miss to be able to open those logs - possibly they have a short lifespan.

All Answers

VinayVinay (Salesforce Developers) 
Hi Bryan,

You can try using Event Monitoring feature which is available as paid version to check detailed logs of API.  You can use the METHOD_NAME, USER_ID, CLIENT_ID to identify who and what was making each call.

Check below references that can give more details.
https://www.salesforce4ever.com/catch-logs-from-your-api-user-thanks-to-automations-and-event-monitoring/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_API_calls.htm

Please mark as Best Answer if above information was helpful.

Thanks,
Bryan Leaman 6Bryan Leaman 6
Unfortunately, the first link you provided is actually wrong about this item:
 
You don’t have Event Monitoring but the inbound or outbound interface triggers some declarative or custom automations
Use the standard Salesforce Debug Logs feature on the API user to catchs the logs. Setting a debug log on your integration user will catch all declarative actions and custom code that are triggered by the API call.
This is therefore more relevant to inbound API calls to Salesforce than outbound calls.

That's our scenario, but I'm not seeing any logs whatsoever even though my trigger code is running. However, there are instances where my custom trigger launches a @Future method for geolocation callouts and *those* do show up in the logs.  I guess I could add monitor statements and generate a log entry in an object of some kind, but if an exception is generated, I'm not sure I'd be able to catch it.
 
Bryan Leaman 6Bryan Leaman 6
Looks like if I start developer console as the API user, then I can see logs, but not if I just start a trace on the API user. Weird.
VinayVinay (Salesforce Developers) 
It mean if you enable debug logs for API user it doesn't show any logs after inbound or outbound API call is made?

Thanks,
Bryan Leaman 6Bryan Leaman 6
These are inbound only, and yes, when I add a trace on the API user from Setup | Debug Logs, no log files are generated. However, I found that if I login as the API user and launch Developer Console, then I *do* see log files being generated that are not visible from Setup | Debug Logs. However, it's been hit & miss to be able to open those logs - possibly they have a short lifespan.
This was selected as the best answer