PayPal Rest API - Update Billing Plan Return URL - c#

I have been using the PayPal Rest API and have successfully created and activated a BillingPlan but I'm having trouble updating said plan's return_url. I think it's something to do with the JSON path I'm using although I'm not sure why!?
Anyway, I am calling the update plan method: https://developer.paypal.com/docs/api/#update-a-plan
A BillingPlan follows the format:
{
"id": "P-94458432VR012762KRWBZEUA",
"state": "ACTIVE",
"name": "T-Shirt of the Month Club Plan",
"description": "Template creation.",
"type": "FIXED",
...
"merchant_preferences": {
"setup_fee": {
"currency": "USD",
"value": "1"
},
"max_fail_attempts": "0",
"return_url": "http://example.com",
"cancel_url": "http://example.com",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE"
},
...
}
I'm using the C# SDK but my request JSON should look very much like:
{
"path": "merchant_preferences",
"value": {
"return_url": "http://example.com/payment/return"
},
"op": "replace"
}
I keep getting responses along the line's of:
{"name":"BUSINESS_VALIDATION_ERROR","details":[{"field":"validation_error","issue":"Invalid
Path provided."}],"message":"Validation
Error.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_VALIDATION_ERROR","debug_id":"2ae68f9f0aa72"}
To sum up - I want to change the billing plan return_url from http://example.com to http://example.com/payment/return.
I've changed the path to various things to no avail. Can anyone help??

You cannot update the plan, once it is set to active. The reason for that restriction is that because there could be possible agreements based on that plan, modifying it would affect the already agreed billing agreements.
However, I agree with your problem statement, that changing the Return URL should not be an issue as this is not a part of agreement, but more of a configuration change. It would be nice to somehow allow updating similar settings in Plan, even after active. I will let the API team know about that.
however, in the mean time, there is no way you would be able to do that. Alternatively, you could possibly create a new plan, and use that instead. Not the answer you are looking for, but a probable solution.

Related

Exact Permissions\actions needed to List Azure Resources using C# rest API

I am trying to list all resources in a Subscription using Rest API Call.
https://management.azure.com/subscriptions/{SubscriptionID}/resources?api-version=2021-04-01
It works fine when I run it with Built-In RBAC Role Reader Permissions. For security reasons, I wanted to avoid having read access to entire scope of subscription. So, I need to create a Custom Role with specific permissions\actions to list all Resources in a Subscription.
I am trying with below Custom Role but not able to get any response from Rest API call.
{
"properties": {
"roleName": "AzResourceTest",
"description": "To test the exact ACLs needed to get Resources List from a Subscription",
"assignableScopes": [
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
],
"permissions": [
{
"actions": [
"Microsoft.Resources/resources/read"
],
"notActions": [],
"dataActions": [],
"notDataActions": []
}
]
}
}
Can someone please suggest what should I use in actions to get resources.
Got it. "Microsoft.Resources/subscriptions/resources/read" is the action for Custom Role to list resources in a subscription

How to automatically make POST REST API requests in c#

I have a project scenario that requires me to make POST REST API requests to url endpoints automatically, so basically I have a view/table in my SQL database and I want to iterate through that view/table to find what changed for a specific column(email) and make a POST request to update only what was changed from view/table columns in SQL and update the JSON in the url endpoint for column(email)
This needs to be done automatically either daily, weekly, or monthly.
Here is a snippet of JSON structure and the column that I want to overwrite is (emailAddress)
{
"additionalAddressInformation": "",
"addressLine": "ADF Test Street",
"addressLine1": "",
"alternatePhone": "",
"city": "TEST",
"companyLocationID": null,
"countryID": 00,
"emailAddress": "adftestingautotask#test.com",
"emailAddress2": null,
"emailAddress3": null,
"extension": "",
"externalID": "",
"facebookUrl": "",
"faxNumber": "",
"firstName": "Azure Data Factory",
"isActive": 0,
"isOptedOutFromBulkEmail": false,
"lastName": "Azure",
"linkedInUrl": "",
"middleInitial": "B",
"mobilePhone": "",
"namePrefix": null,
"nameSuffix": null,
"note": "",
"receivesEmailNotifications": true,
"phone": "(000) 000-000",
"primaryContact": false,
"roomNumber": "",
"state": "NY",
"title": "ADF Developer",
"twitterUrl": "",
"zipCode": "0000",
}
What I have done so far:
I have made some researches and came across a library called HangFire, not sure if is the correct way to approach my project scenario.
I have created a pipeline in Azure Data Factory and was able to POST manually, but I am not sure if I can use Web activity to create the POST call to include column (email) in the POST call as a parameter or variable.
Any recommendation or suggestions would help.
Thanks in advance
Yes, HangFire is one of the methods - if you prefer creating an app that takes care of it's own and just runs on server - it's more then enough.
Alternative approach would be to use tools like Jenkins to schedule a repeating task on the server side.
It all depends in this case on preference and available resources - more complicated but self-sufficient app vs simpler app that just scan the db and use post fired up by third party solution.
And please, do mind that my answer is opinion-based - I don't think that there is a one proper way of handling this situation without going into much detail.

Google Youtube API provides wrong data

I have a trouble with YouTube API. I have an experience in many API services and first time I encountered such strange work of this API.
Problem description:
First, I want to get subscribers of my channel. I'm developing this tool for my friend, but I take my own channel for testing purposes. So, doesn't matter how (through Web Interface of my C# tool), but I always get wrong data about my subscribers.
This is my json response:
...
"pageInfo": {
"totalResults": 17,
"resultsPerPage": 5
}, ...
Actual count of subscribers is 17. It is ok. But next, I have a list with subscribers description:
"items": [
{
"kind": "youtube#subscription",
"etag": "...",
"id": "...",
"subscriberSnippet": {
"title": "chris chandler",
"description": "",
"channelId": "UCbl-PjR7SwAQkGi2nUlZbMg",
...
}
},
And count of this blocks is 8.
I tried to set maxResults to 50 for getting all results in one page. But I always have 8 subscribers. I don't know why.
I tried tool with my friend's account. His actual count of subscribers is 385. But API shows only 301. Also I tried to get list of my subscriptions. Actual it is 107, but I get only about 80.
I've tested it with Web interface here:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.list?part=subscriberSnippet&maxResults=5&mySubscribers=true
P.S. You can think, that some of YouTube data doesn't update momentarily. But I have constant amount of subscribers on my test channel about 3 years (It is about channel with 17 subscribers).

SCIM Deserialization Issue in .NET

As a newcomer to the SCIM (System for Cross-domain Identity Management) standard, please excuse any ignorance as I'm on the learning curve trying to figure out how to make clean/simple requests to provision users, delete users and modifiy users.
I'm attempting to use C#/.NET to make HTTP REST requests for a user via SCIM, using the System.Net.Http.HttpClient
https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx
I can do this successfully and get a JSON response from the server, however in order to easily read the response object and manipulate it, I want to deserialize it.. After much reading around trying to use things like JsonConvert, dynamic etc. I stumbled upon a Microsoft nuget library which seemed to hint at being useful. Sadly there don't appear to be any docs for it*
UPDATED:
One of the authors has updated the nuget page with a link to a blog post which goes some way to explaining usage.
Microsoft.SystemForCrossDomainIdentityManagement
https://www.nuget.org/packages/Microsoft.SystemForCrossDomainIdentityManagement/
The SCIM provider I'm attempting to get data from is Facebook, using the example they publish on their site for getting a user by email:
https://developers.facebook.com/docs/facebook-at-work/provisioning/scim-api#getuserbyemail
Here's a code sample in C# which attempts to get the user from the SCIM service and deserialize them. I'm finding that the queryResponse I get back is deserialized correctly as the properties are populated, however the Core1EnterpriseUser which is the first and only of the resource objects, has null/default properties.
var userName = "foo.bar#foobar.com";
var response = await client.GetAsync($"Users?filter=userName%20eq%20%22{userName}%22");
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var jsonResponseProperties = await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject<Dictionary<string, object>>(json); });
var userFactory = new QueryResponseJsonDeserializingFactory<Core1EnterpriseUser>();
var queryResponse = userFactory.Create(jsonResponseProperties);
if (queryResponse.TotalResults == 1)
{
var user = queryResponse.Resources.First();
var id = user.Identifier; // this and other properties are null/false etc.
}
}
Here's a sample of the JSON that is returned by the service when I query it:
{
"schemas": [
"urn:scim:schemas:core:1.0"
],
"totalResults": 1,
"itemsPerPage": 10,
"startIndex": 1,
"Resources": [
{
"schemas": [
"urn:scim:schemas:core:1.0",
"urn:scim:schemas:extension:enterprise:1.0",
"urn:scim:schemas:extension:facebook:starttermdates:1.0",
"urn:scim:schemas:extension:facebook:suppressclaimemail:1.0"
],
"id": 180383108978226,
"userName": "foo.bar\u0040foobar.com",
"name": {
"formatted": "Foo Bar",
"familyName": "Bar",
"givenName": "Foo"
},
"title": "Vice President",
"active": true,
"emails": [
{
"primary": false,
"type": "work",
"value": "foo.bar\u0040foobar.com"
}
],
"urn:scim:schemas:extension:enterprise:1.0": {
"department": "IT"
},
"urn:scim:schemas:extension:facebook:starttermdates:1.0": {
"startDate": 0,
"termDate": 0
}
}
]
}
UPDATE:
I'm in dialog with one of the authors of the project and he kindly pointed me at this blog post:
http://blogs.technet.com/b/ad/archive/2015/11/23/azure-ad-helping-you-adding-scim-support-to-your-applications.aspx
He has also updated the nuget library which now includes support for v1 of SCIM, also pointing out that as the JSON data suggests the version used by Facebook is v1: "urn:scim:schemas:core:1.0" so now I can use Core1 rather than attempting to use Core2 classes (I've updated the question above to use Core1EnterpriseUser).
I'm still not able to get my response deserialized correcty at present and will update the question with more information as I have it.
Again, I don't have to use this library if it becomes apparent that it's not easily going to work, as I know the brief description on nuget suggests it was created for Azure AD.
However I'd appreciate any advice on how this type of thing could/should be done as I'm sure there must be a lot of people out there using SCIM - how do you parse your responses/generate your requests such that you have actual objects? Can you automatically parse responses for schemas in order to augment the object with the correct properties?
I was up late last night hand crafting some model classes to handle the response objects - which I do seem to have working. If I can't get the nuget library working (the preferred option) then I'll have to go with my own. :/
Thanks again
peteski
Although I'm still none the wiser about best practices with SCIM, I've managed to get the code working now - with massive thanks to one of the nuget library's authors Craig McMurtry at Microsoft!
There were a few things to iron out along the way, such as the nuget package being updated to include the previous support for older v1 SCIM objects. But here's a snippet of what worked based on the example in my question, but it turned out to be using the Newtonsoft serializer. :(
In the code above the line:
var jsonResponseProperties = await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject<Dictionary<string, object>>(json); });
Was replaced with:
var jsonResponseProperties = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(json);
Et voilĂ ! My object's properties are now deserializing...

Nextpagetoken not working as desired

There are a lot of videos in the channel. Where as 'nextPageToken' only
iterates about 570 of them on my code.
Perhaps not a lib issue because the same happens on https://developers.google.com/youtube/v3/docs/search/list. After about only 10 pages the nextPageToken disappears.
You should using channel+playlistItems API to get ALL channel videos, not search API.
Kindly check it out on https://developers.google.com/youtube/v3/docs/channels/list#try-it.
Example, i set the channel id UCi-Lb1gFer4U7tkqFA1adiQ and part parameter as contentDetails.
the example of response is:
"items": [
{
"id": "UCi-Lb1gFer4U7tkqFA1adiQ",
"kind": "youtube#channel",
"etag": "\"NT-fDeVOLsFPouddIzcaWbd0fJw/sQKRHjGLTreNbWWrW3gIojOKiEk\"",
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUi-Lb1gFer4U7tkqFA1adiQ"
}
}
}
]
Then you know the uploads playlist id now, UUi-Lb1gFer4U7tkqFA1adiQ, so you visit
https://developers.google.com/youtube/v3/docs/playlistItems/list
Put UUi-Lb1gFer4U7tkqFA1adiQ as the playlistId, then you would able to get all the videos by pagination.
p/s: please provide your channel id, if you still experience the problem

Categories