Pages

Tuesday, September 16, 2014

Send tweets from AX via the Retail module

Once again I fell over some objects with interesting names in the retail code. This time I learned that you can update Twitter and Facebook from AX.

In the following I'll describe the Twitter setup.

First of all, you need to setup an application under your Twitter account. Go to https://apps.twitter.com/ to do that. Under settings, you need to fill in:
  • Name: This will be the name of your application. Mine is called PalleAgermarkTest.
  • Description: This shows up when for example you later on link the application to be able to use your Twitter account.
  • Website: This should be a website where users can download the application. Since I don't have a real application, I have just put the address of my blog.
  • Callback URL: This is needed when AX links the application to your Twitter account. Again, the address is not important (but an address is needed) for this demonstration and I have again put the address of my blog here.
On the API tab of the setup, you'll get an API key and an API secret. You will need these in AX.


On the Permissions tab, give the application write access to the Twitter accounts that sign up to the application:

That's it for Twitter.

Go to Retail \ Setup \ Parameters \ Retail parameters to setup some seed data for the retail module. Click the Initialize button:



Now in AX, go to Retail \ Setup \ Parameters \ Retail shared parameters and enter the API key secrets from above:


Then go to Sales and marketing \ Setup \ Campaigns \ Media types and add Twitter as a media type:


Now when clicking the Link account button, you should get the option to link your Twitter account (the screen clip is in Danish, but you should be able to get the idea):


So now all the bits and pieces are setup, and a very simplified piece of code like this example is able to post to Twitter:

static void Tweet(Args _args)
{
    smmCampaignMediaTypeGroup           mediaTypeGroup;
    RetailMediaChannelConnectorSettings settings;
    RetailMediaChannelTwitterConnector  connector;
    RetailMediaChannelMessage           message;

    select firstOnly TableId from mediaTypeGroup
        where mediaTypeGroup.CampaignMediaTypeDescription == 'Twitter'
    join settings
        where settings.smmCampaignMediaTypeGroup == mediaTypeGroup.CampaignMediaTypeId;

    connector = RetailMediaChannelTwitterConnector::construct(settings);
    message = RetailMediaChannelMessage::construct();
    message.parmMessage("Tweet from AX");
    connector.push(message);
}

The result:


2 comments:

Atul Singh said...

hi Palle AgerMark,

Thank you very much for the interesting post.

I am configuring send tweet from Ax but In Media Type form "Link Account" button is disable. Please help why is it disabled?


Thank you!
Atul Kumar

Atul Singh said...

hi Palle Agemark,

In media type form link Account is disable please help.

Thank You!