crowdin / crowdin-api-client-dotnet

.NET client library for Crowdin API
https://www.nuget.org/packages/Crowdin.Api/
MIT License
50 stars 27 forks source link

StringBatchOperations return null #212

Closed kevinLourencoDev closed 6 months ago

kevinLourencoDev commented 7 months ago

Hi,

In both version 2.18 and 2.19, StringBatchOperations seems to not send the correct ResponseList and send return result: null

Here is the simple client call:

        public Task<ResponseList<SourceString>> BulkEditSourceStrings(int projectId, List<StringBatchOpPatch> patches)
        {
            return _client.SourceStrings.StringBatchOperations(projectId, patches);
        }

And there is how we created patches:

 var patches = sourceStrings.Select(sourceString => new CrowdinSourceStrings.StringBatchOpPatch()
            {
                Operation = Crowdin.Api.PatchOperation.Add,
                Value = new CrowdinSourceStrings.SourceString()
                {
                    Identifier = "test",
                    Text = "test",
                    Context = "test",
                    FileId = 1,
                    IsHidden = false
                }
            }
                ).ToList();

            var response = await _crowdinClientWrapper.BulkEditSourceStrings(projectId, patches);

Patches seem to be well formatted if we consider it's required to be only an array of {Crowdin.Api.SourceStrings.StringBatchOpPatch} following https://developer.crowdin.com/api/v2/#operation/api.projects.strings.post

High chance the feature is simply not working, since my implementation is simple. Let me know if you need more informations !

andrii-bodnar commented 7 months ago

Hi @kevinLourencoDev, could you please try the same request in Postman to define if whether it's the API issue or the API Client issue? Thank you!

kevinLourencoDev commented 7 months ago

Sure, i tried a simple curl one:

curl -X PATCH "https://client.api.crowdin.com/api/v2/projects/11/strings" \
-H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '[{
  "op": "add",
  "path": "/-",
  "value": {
    "text": "new added string",
    "identifier": "a.b.c",
    "context": "context for new string",
    "fileId": 1,
    "isHidden": false
  }
}]'

And we have as we would like a result:

{"data":[{"data":{"id":627408,"projectId":1,"branchId":null,"identifier":"a.b.c","text":"new added string","type":"text","context":"a.b.c\ncontext for new string","maxLength":0,"isHidden":false,"isDuplicate":false,"masterStringId":null,"hasPlurals":false,"isIcu":false,"labelIds":[],"createdAt":"2023-12-01T14:12:42+00:00","updatedAt":null,"fileId":1701,"directoryId":1537,"revision":16}}]}

I confirm the issue might come from API Client !

andrii-bodnar commented 7 months ago

@kevinLourencoDev thanks a lot for the details and the confirmation!

kevinLourencoDev commented 7 months ago

@andrii-bodnar do you have any visibility on this error base on the priority of it? Would you need more help to fix it?

andrii-bodnar commented 7 months ago

@kevinLourencoDev since this is an API Client issue, we'd be happy to accept contributions!

Feel free to read the contributing guidelines for more details.

Zahid92 commented 6 months ago

Hi @kevinLourencoDev,

Could you try using this

var patches = sourceStrings.Select(sourceString => new CrowdinSourceStrings.StringBatchOpPatch()
            {
                Operation = Crowdin.Api.PatchOperation.Add,
                Value = new CrowdinSourceStrings.AddStringRequest()
                {
                    Identifier = "test",
                    Text = "test",
                    Context = "test",
                    FileId = 1,
                    IsHidden = false
                }
            }
                ).ToList();

            var response = await _crowdinClientWrapper.BulkEditSourceStrings(projectId, patches);

As new source strings are added using AddStringRequest Object rather than SourceString.

Zahid92 commented 6 months ago

Hi @andrii-bodnar, I think the user must not be able to instantiate a source string object. It should always come from API only.