Search code examples
c#.netrest

C# .NET Implement DHL API Tracking


I have a negative score for this question and I can't submit any new questions on stackoverflow. I can't delete this question or make it generic as it referred to a particular API. Any ideas?

I have tried adding the Service Reference to my Project but this is not working?

https://api-eu.dhl.com/tracking

I am getting the following error when trying to add the Service Reference

Metadata contains a reference that cannot be resolved: 'https://api-eu.dhl.com/tracking'. The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''. The remote server returned an error: (401) Unauthorized. If the service is defined in the current solution, try building the solution and adding the service reference again.


Solution

  • You receive that error because you pass a wrong key, and by reading the comments I see that you don't have an application registered yet.

    The following headers are needed to consume DHL API endpoints.

    'Accept': 'application/json',
    'DHL-API-Key': 'ApiKeyHere'
    

    There is a written sample in Python https://developer.dhl.com/api-reference/shipment-tracking#get-started-section%example-requests-to-the-api

    If you need help with writing it in C#, you can follow this answer https://stackoverflow.com/a/39670617/5394806