cancel
Showing results for 
Search instead for 
Did you mean: 

Update yMKT Interaction status from SAP CRM!

former_member611643
Participant
0 Kudos

Hello, Friends!

I'm absolutely new in SAP yMKT and need some help.
I have interaction in yMKT with the current IA_STATUS = 'PROMO_OUTBOUND'.

This status was assigned to this field when I sent the promo to SAP CRM!
Now I want to update this IA_STATUS to 'PROMO_ASSIGNE' from SAP CRM!

But I don't know how to do this because I don't have enough experience in SAP yMKT.
Can anybody help me with some advice or some 'step-by-step' guide?
Thanks!

Accepted Solutions (0)

Answers (1)

Answers (1)

SCHNEIDERT
Active Contributor
0 Kudos

Hi Sigy,

the replication is done via SAP CPI? Do you have access to it?

I think the best point for you to start is maybe here with the Integration package for SAP Marketing Cloud.

I can see there's an iFlow for the confirmation of the activity replication. So as you described I think the status is set through the confirmation after you replicated your Activity from SAP Marketing to SAP CRM.

In the iFlow there is the StatusCode field. I think you should check this one in your iFlow and see how it is set. After that you can adapt your mapping according to your needs. But not sure if this is really the field you are using.

Hope that helps.

BR Tobias

former_member611643
Participant
0 Kudos

Thanks a lot, Tobias for your feedback!

Actually, I thought the solution should look like this:
1. Create RFC-destination and put there the API_MKT_INTERACTION_SRV URL.
2. By using CL_HTTP_CLIENT, CL_REST_HTTP_CLIENT, /UI2/CL_JSON put data to OData entityset
3. Call the UPDATE method for the interaction table.

Am I right or those steps are incorrect?


SCHNEIDERT
Active Contributor
0 Kudos

Hi dkolodin,

okay I understand. So yes I think the steps are correct.

For doing an update you should call the /$batch endpoint and use PATCH method.

Indeed then you should use the InteractionStatus field.

But what's exactly your problem now if you already know which service to use and how to call it and update the field of your choice? 🙂

BR Tobias

former_member611643
Participant
0 Kudos

So, my problem is:
1. Wich type of RFC I should create ('3' or 'G' or 'H')?
2. If 'G' what should I put in setting field PathPrefix? (it should be /sap/opu/odata/SAP/API_MKT_INTERACTION_SRV) ?
3. How should I call the /$batch endpoint and use PATCH method?

SCHNEIDERT
Active Contributor

Sorry, I'm not sure about the type of RFC. Maybe saurabhkabra2009 can help concerning that question.

I can only show you how I call it using Postman, maybe that helps.

So I do a POST to the batch endpoint like that https://my123456-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_INTERACTION_SRV/$batch

I've attached a sample payload: payload-interaction-update.txt

Of course you have to provide a x-csrf-token in the header and add the correct value for the Content-Type.

former_member226
Employee
Employee

Hi Sigy,

In addition to what Tobias already mentioned, You need to create an RFC of type 'G'(HTTP Connections to External Server) in order to connect SAP CRM to SAP yMKT. In ideal case, you should not connect directly with SAP yMkt from SAP CRM. Rather connection from CRM should point to CPI and let CPI/PI take the message to the target system. When putting type 'G' for RFC you can mention CPI hostname(until .com) as "Host" and rest of the string as path prefix.

rfc-cpi.png

If you are using CPI/HCI to connect from SAP CRM to SAP PI then you just need to call the CPI endpoints using CL_HTTP_CLIENT class. But if you are directly connecting from SAP CRM to SAP yMKT in batch mode via ABAP, then you can go to SAP API Business Hub (https://api.sap.com) and try out the batch mode and click "Code Snippet" which will generate the code you need for triggering the batch call.

batch-mode-in-abap.png

former_member611643
Participant
0 Kudos

I've created a test app and always get the error 'CSRF token validation failed'!

Here's my app code, maybe somebody can tell me my mistakes?

REPORT ztest_test_api.

DATA: lo_http_client TYPE REF TO if_http_client.
DATA: response TYPE string.
DATA: request TYPE string.


CALL METHOD cl_http_client=>create_by_url
  EXPORTING
    url                = 'http://<myhost>:<myport>/sap/opu/odata/sap/API_MKT_INTERACTION_SRV/'
  IMPORTING
    client             = lo_http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4.

lo_http_client->propertytype_accept_cookie = if_http_client=>co_enabled.
lo_http_client->request->set_method('GET').
lo_http_client->request->set_header_field( name = 'sap-user'  value = 'myuser' ).
lo_http_client->request->set_header_field( name = 'sap-password'  value = `mypassword` ).
lo_http_client->request->set_header_field( name = 'X-CSRF-Token' value = 'Fetch' ).
lo_http_client->request->set_header_field( name = 'X-Requested-With' value = 'X' ).

CALL METHOD lo_http_client->send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    http_invalid_timeout       = 4
    OTHERS                     = 5.

DATA(lv_token) = lo_http_client->request->get_header_field( name = 'X-CSRF-Token' ).

IF sy-subrc = 0.
  CALL METHOD lo_http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 5.
ENDIF.

IF sy-subrc <> 0.

ENDIF.

response = lo_http_client->response->get_cdata( ).

CONCATENATE request'{' INTO request.
CONCATENATE request '"InteractionUUID": "01234567-89ab-cdef-0123-456789abcdef",'  INTO request.
CONCATENATE request '"InteractionContactOrigin": "string",' INTO request.
CONCATENATE request '"InteractionContactId": "string",' INTO request.
CONCATENATE request '"CommunicationMedium": "string",' INTO request.
CONCATENATE request '"InteractionType": "string",' INTO request.
CONCATENATE request '"InteractionTimeStampUTC": "/Date(1492098664000)/",' INTO request.
CONCATENATE request '"InteractionSourceObjectType": "string",' INTO request.
CONCATENATE request '"InteractionSourceObject": "string",' INTO request.
CONCATENATE request '"MarketingArea": "string",' INTO request.
CONCATENATE request '"CampaignID": "string",' INTO request.
CONCATENATE request '}' INTO request.

lo_http_client->request->set_method('POST').

" headers

lo_http_client->request->set_header_field( name = 'Content-Type'  value = 'application/json' ).
lo_http_client->request->set_header_field( name = 'Accept'        value = 'application/json' ).
lo_http_client->request->set_header_field( name = 'X-CSRF-Token'  value = lv_token ).

lo_http_client->request->set_cdata( data = request  ).


CALL METHOD lo_http_client->send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    http_invalid_timeout       = 4
    OTHERS                     = 5.

IF sy-subrc = 0.
  CALL METHOD lo_http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 5.
ENDIF.

IF sy-subrc <> 0.

ENDIF.

response = lo_http_client->response->get_cdata( ).

WRITE: 'response: ', response.
former_member226
Employee
Employee

Hi,

In addition to passing x-csrf-token to the request header, you also need to copy the existing session cookie retrieved from response header of first GET request to second request header as well, else system might consider it as a new request and old csrf will not be valid any more.

Please also check out https://blogs.sap.com/2014/07/11/issues-with-csrf-token-and-how-to-solve-them/