|
| 1 | + |
| 2 | +# Migration Guide |
| 3 | + |
| 4 | +This guide helps you migrate from this SDK to new [Csharp SDK](https://github.com/apideck-libraries/sdk-csharp) |
| 5 | + |
| 6 | +## Key changes |
| 7 | + |
| 8 | +1. **Installation** |
| 9 | + |
| 10 | +```sh |
| 11 | +# Old package |
| 12 | +dotnet add package Apideck |
| 13 | + |
| 14 | +# New package |
| 15 | +dotnet add package ApideckUnifySdk |
| 16 | +``` |
| 17 | + |
| 18 | +2. **SDK Initialization** |
| 19 | + |
| 20 | + |
| 21 | +```csharp |
| 22 | +// Old SDK |
| 23 | +Configuration config = new Configuration(); |
| 24 | +config.AddApiKey("Authorization", "API_KEY"); |
| 25 | +config.AddApiKeyPrefix("Authorization", "Bearer"); |
| 26 | +var apiInstance = new CrmApi(config); |
| 27 | + |
| 28 | +// New SDK |
| 29 | +var sdk = new Apideck( |
| 30 | + apiKey: "<YOUR_BEARER_TOKEN_HERE>", |
| 31 | + consumerId: "test-consumer", |
| 32 | + appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX" |
| 33 | +); |
| 34 | +``` |
| 35 | + |
| 36 | +3. **Method Naming Changes** |
| 37 | + |
| 38 | +```csharp |
| 39 | +// Old SDK |
| 40 | +var result = apiInstance.CompaniesAll(raw, consumerId, appId, serviceId); |
| 41 | + |
| 42 | +// New SDK |
| 43 | +var req = new AccountingCompaniesListRequest() { |
| 44 | + ServiceId = "salesforce" |
| 45 | +}; |
| 46 | +var result = await sdk.Accounting.Companies.ListAsync(req); |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | +4. **Request/Response Structure** |
| 51 | + |
| 52 | +```csharp |
| 53 | +// Old SDK |
| 54 | +var result = apiInstance.CompaniesAll(); |
| 55 | +foreach (var company in result.Data) { |
| 56 | + Console.WriteLine(company.Name); |
| 57 | +} |
| 58 | + |
| 59 | +// New SDK |
| 60 | +var req = new AccountingCompaniesListRequest() { |
| 61 | + ServiceId = "salesforce", |
| 62 | + Filter = new CompaniesFilter() { |
| 63 | + // Add filters here |
| 64 | + } |
| 65 | +}; |
| 66 | +var result = await sdk.Accounting.Companies.ListAsync(req); |
| 67 | + |
| 68 | +``` |
| 69 | + |
| 70 | +Every response includes httpMeta which provides access to the raw HTTP request and response: |
| 71 | +The `httpMeta` object is essential because it provides detailed information about the HTTP request and response, which can be crucial for debugging and logging purposes. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +5. **Method Naming Convention Changes** |
| 76 | + |
| 77 | +The new SDK uses a more consistent and intuitive naming convention. Here's how the old methods map to new ones: |
| 78 | + |
| 79 | +| Old Method | New Method | |
| 80 | +|------------|------------| |
| 81 | +| CompaniesAll | Companies.ListAsync | |
| 82 | +| CompaniesAdd | Companies.CreateAsync | |
| 83 | +| CompaniesOne | Companies.GetAsync | |
| 84 | +| CompaniesUpdate | Companies.UpdateAsync | |
| 85 | +... |
| 86 | + |
| 87 | +6. **Async/await support for all API calls** |
| 88 | + |
| 89 | +The new SDK fully supports async/await patterns by default. |
| 90 | + |
| 91 | +```csharp |
| 92 | +// Old SDK - synchronous |
| 93 | +var result = apiInstance.CompaniesAll(); |
| 94 | + |
| 95 | +// New SDK - async/await |
| 96 | +var result = await sdk.Accounting.Companies.ListAsync(req); |
| 97 | +``` |
| 98 | + |
| 99 | +The previous SDK had a [known issue](https://github.com/apideck-libraries/dotnet-sdk?tab=readme-ov-file#async-functionality-with-applied-filters) where filters didn't work correctly with async operations. This has been completely resolved in the new SDK. |
| 100 | + |
| 101 | + |
| 102 | +7. **Error handling** |
| 103 | + |
| 104 | +```csharp |
| 105 | +// Old SDK |
| 106 | +try { |
| 107 | + var result = apiInstance.CompaniesAll(raw, consumerId, appId, serviceId); |
| 108 | +} |
| 109 | +catch (ApiException e) { |
| 110 | + Console.WriteLine("Exception when calling API: " + e.Message); |
| 111 | + Console.WriteLine("Status Code: " + e.ErrorCode); |
| 112 | + Console.WriteLine("Detail: " + e.ErrorContent); |
| 113 | +} |
| 114 | + |
| 115 | +// New SDK |
| 116 | +try { |
| 117 | + var result = await sdk.Accounting.Companies.ListAsync(req); |
| 118 | +} |
| 119 | +catch (Exception ex) { |
| 120 | + if (ex is BadRequestResponse badRequest) { |
| 121 | + // Handle 400 error |
| 122 | + } |
| 123 | + else if (ex is UnauthorizedResponse unauthorized) { |
| 124 | + // Handle 401 error |
| 125 | + } |
| 126 | + else if (ex is ApideckUnifySdk.Models.Errors.APIException apiError) { |
| 127 | + // Handle other API errors |
| 128 | + } |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +For more information about error handling, please check our [documentation](https://github.com/apideck-libraries/sdk-csharp/tree/main?tab=readme-ov-file#error-handling) |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +## Summary of breaking Changes |
| 137 | + |
| 138 | +1. Package name has changed from Apideck to ApideckUnifySdk |
| 139 | +2. All API methods now follow a consistent naming pattern and are async by default |
| 140 | +3. SDK initialization has been simplified with a unified configuration object |
| 141 | +4. More specific error types for better error handling |
| 142 | +5. Request/response models have been updated for better type safety |
| 143 | +6. All operations now use dedicated request objects for parameters |
| 144 | + |
| 145 | + |
| 146 | +## Need help? |
| 147 | + |
| 148 | +If you encounter any issues during migration: |
| 149 | + |
| 150 | +1. Checkout out our [documentation](https://github.com/apideck-libraries/sdk-csharp/tree/main?tab=readme-ov-file#apideckunifysdk) |
| 151 | +2. Open an issue on our [GitHub repository](https://github.com/apideck-libraries/sdk-csharp/issues) |
| 152 | +3. Contact our support at `[email protected]` |
0 commit comments