Issues adding subscriber to service in ACS API

AditThom

06-04-2019

I am trying to add a profile as a subscriber via the ACS API.  I have attempted both methods described in the API documentation here...  Adobe Campaign Standard API  and here Campaign Standard: use APIs to optimize your cross-channel campaigns. ​(the latter seems to assume you are only using the extended api endpoints, but I figured out how to get past that.

I can successfully retrieve a profile using the byEmail filter and retrieve the PrimaryKey and the  href value from the profile subscriptions result:

Note (images are readable if you open them in a new tab)

GetProfile.JPG

Likewise I can successfully retrieve a service by its name using the byText filter and retrieve the Primary Key and the href from the service subscriptions result.

1728027_pastedImage_3.png

I can then construct the payload for adding a subsciber to a service:

{"subscriber":{"Pkey":"@XQ2pwu9sH-zI7KunbV7NZvQ6bLD8Drov_niGPRknuibH3hK4uydXD4f7R_nNXIkVncAVkcdWLDKfzt_GvrUUyGBSoG0"}}

and the opposite for adding a service to the subsciber.

{"service":{"Pkey":"@jUmwrrvNrjg_9b9zsQxli_4J7S_fMRkKbuXzoXB5z9acmEA8zz23JLZum3OCnrNFRcKmNDMR0x2VxVaYglsnF4ckVsQ"}}

Neither is working and each gives me different behaviors... if I try post the subscriber payload to the services subscription url, it gives me a duplicate key error because no matter what profile id it is passing it is trying to insert  isubscriberid 0... tells me it is not liking or not finding the subscriber by the Pkey and so I get this message.

PGS-220000 PostgreSQL error: ERROR:  duplicate key value violates unique constraint "nmssubscriptionrcp_key"

DETAIL:  Key (iserviceid, isubscriberid)=(1591517, 0) already exists.

If I reverse the notion and try the other method posting the service PKey to the profile subscription link then I get a permissions error.

Anyone have a suggestion where to go from here?  The subscribe to service function I have written is below...

  public async Task<OperationResponse> SubscribeToServiceAsync(string email, string servicename) {

            OperationResponse result = new OperationResponse();

            result.OperationRequest = ("Subscribe " + email + " to service: " + servicename);

            Profile p = GetProfile(email);

            if (p.Subscriptions.Services.Exists(a => a.Name == servicename)) {

                result.Success = true;

                result.Message = "Previously Subscribed";

            }

            else {

                Service srv = GetService(servicename);

                ApiAccessToken AccessToken = GetAccessToken();

                HttpClient client = new HttpClient();

                var httpRequestMessage = new HttpRequestMessage {

                    Method = HttpMethod.Post,

                    RequestUri = new Uri(srv.SubscriptionsUrl),

                    Headers = {

                            {HttpRequestHeader.ContentType.ToString(),"application/json" },

                            {HttpRequestHeader.Authorization.ToString(), AccessToken.HttpRequestHeaderText },

                            {HttpRequestHeader.CacheControl.ToString(), "no-cache" },

                            {"X-Api-Key", APIKey }

                        },

                    Content = new StringContent("{\"subscriber\":{\"Pkey\":\"" + p.APIUniqueID + "\"}}")

                };

                System.Diagnostics.Debug.WriteLine(await httpRequestMessage.Content.ReadAsStringAsync());

                Task<HttpResponseMessage> t = client.SendAsync(httpRequestMessage);

                t.Wait();

                HttpResponseMessage response = t.Result;

                using (HttpContent respContent = response.Content) {

                    string toLoad = await respContent.ReadAsStringAsync();

                    System.Diagnostics.Debug.WriteLine(toLoad);

                    dynamic payload = JObject.Parse(toLoad);

                }

            }

            return result;

        }

Accepted Solutions (1)

Accepted Solutions (1)

craigthonis

Employee

24-04-2019

Hey Thom,

Circling back on this to close the loop.  As discussed in your Support ticket, it was found that the API call referencing PKey is case sensitive.  So in the original examples, we see "Pkey" is referenced.  When using "PKey" all calls were executed correctly without issue.

Correct Payload format:

{"subscriber":{"PKey":"@..."}}

Regards,

Craig

Answers (2)

Answers (2)

AditThom

09-04-2019

This is still an issue, but I have a bit more information.  We added some new services and I discovered that the first profile I try to subscribe via the API does NOT return with the duplicate key error, but even though it found the appropriate service it seems to not make the connection to the profile and so it fails, silently, and inserts a subscription record with an id of 0.  All subsequent subscribe calls then also do not find the profile and so the duplicate key error occurs.

The picture below shows the return from the first call and the null user returned.

NullProfile.PNG