Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set custom CSS branding #2463

Closed
i-am-shodan opened this issue Apr 29, 2024 · 7 comments
Closed

Unable to set custom CSS branding #2463

i-am-shodan opened this issue Apr 29, 2024 · 7 comments
Labels

Comments

@i-am-shodan
Copy link

Describe the bug

I want to set Custom CSS branding with the MS Graph API. The branding object has setters for a byte[] containing css but I get an exception when trying to set this. See below for example code

Expected behavior

  • Working example code
  • Calling PatchAsync with the CustomCss byte[] set should result in success

How to reproduce

// code to get GraphServiceClient with OrganizationalBranding.ReadWrite.All scope
var branding = await service.Organization[tenantId].Branding.GetAsync();
branding.CustomCSS = someCssFileAsByteArray;
await service.Organization[tenantId].Branding.PatchAsync(branding);
// Exception Unexpected contents in request body, error 400
// code to get GraphServiceClient with OrganizationalBranding.ReadWrite.All scope
var ms = new MemoryStream(someCssFileAsByteArray);
ms.Position = 0;
await service.Organization[tenantId].Branding.CustomCSS.PutAsync(ms);
// Exception Uri is invalid for a PUT operation. The URI must refer to an entity., error 405

SDK Version

5.30.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

.net6

### Other information

_No response_
@i-am-shodan i-am-shodan added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Apr 29, 2024
@andrueastman
Copy link
Member

Thanks for raising this @i-am-shodan

Any chance you can post the question at the link below? Unfortunately, as this repo is mainly intended for SDK related issues and as there is no REST API documentation as to how to update this property, we may need guidance of the API owners here. It would be great if you could post back the link of the same so that anyone who comes across this may also follow it up.

https://aka.ms/askgraph

@andrueastman andrueastman added Needs: Author Feedback and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Apr 30, 2024
@i-am-shodan
Copy link
Author

Looking at this it does look like the SDK is using the wrong logic https://learn.microsoft.com/en-us/graph/api/organizationalbranding-update?view=graph-rest-1.0&tabs=http

@i-am-shodan
Copy link
Author

using (var ms = new MemoryStream(requestBody.CustomCSS))
{
  var req = service.Organization[tenantId].Branding.CustomCSS.ToPutRequestInformation(ms);
  var uri = req.URI;
}

Then the URI I get out it is https://graph.microsoft.com/v1.0/organization/[tenant]/branding/customCSS

The docs say to use the following URI for stream types - which customcss is. Which also matches what the error message is saying.

PUT /organization/{organizationId}/branding/localizations/{organizationalBrandingLocalizationId}/{Stream object type such as backgroundImage}

So I think this is a SDK problem

@i-am-shodan
Copy link
Author

Yes this is a SDK problem. Here is the code required. Note this is almost exactly the same issue as microsoftgraph/msgraph-beta-sdk-dotnet#653. The SDK is sending:

  • The wrong content type
  • using the wrong URL
using (var ms = new MemoryStream(requestBody.CustomCSS))
{
  var req = service.Organization[tenantId].Branding.CustomCSS.ToPutRequestInformation(ms);
  req.URI = new Uri($"https://graph.microsoft.com/v1.0/organization/{tenantId}/branding/localizations/0/customCSS");

  req.Headers.Remove("Content-Type");
  req.Headers.Add("Content-Type", "text/css");
  var res = await service.RequestAdapter.SendPrimitiveAsync<Stream>(req);
}

@andrueastman
Copy link
Member

Thanks for the extra information, could you confirm that the following works out? It looks like the latest versions of the SDK have the relevant request builders to make the request as below.

            using var ms = new MemoryStream();
            var response = await graphClient.Organization["tenantId"].Branding.Localizations["0"].CustomCSS.PutAsync(ms, "text/css");

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants