Hi I'm trying to use Mailchimp library with mailchimp php sdk. I'm trying to change the HTML content with api call using this.
$MailChimp = new \DrewM\MailChimp\MailChimp('api key');
$MailChimp->verify_ssl = false;
$MailChimp->patch('templates/temp id', [
'name' => 'my template',
'html' => '<p>dsd</p>'
]);
if ($MailChimp->success()) {
print_r($result);
} else {
echo $MailChimp->getLastError();
}
since we can change the name without any issue it seems like the issue relies on 'html' => '<p>dsd</p>'. It would be great help if someone can check.
error message I got is,
400: The resource submitted could not be validated. For field-specific
details, see the 'errors' array.
This error happens when an API request attempts to change a template that doesn't allow custom HTML. On the templates page in MailChimp, any template that's labeled as 'Drag and drop' will fail to update the HTML with an API request. It needs to be labeled as 'Code your own'.
The format can't change once it's set, so you'll have to create a new template and choose 'Code your own' on the creation page, then it will allow the html request parameter to be updated using the API.
Also, if you need to use the same design from your old template, you can export it as HTML, but the drag and drop features won't work when you import it to the new template.
Hope this helps!
Related
I have campaing which uses template and I need to send this campaign via Marketing API with 5 (or more) latest job offers. I trying to find the way to do it.
I've tried to use Template Language on simple example.
I've added this block to template: <h3 mc:edit="article_title">Title</h3>
And then I try to update campaign content with PHP library mailchimp/marketing:3.0.27:
$campaign = $this->mailchimp->campaigns->setContent($campaignId, [
'template' => [
'id' => (int) $templateId,
'sections' => [
'article_title' => 'Test title',
],
],
]);
This request runs successfully, but I don't see any changes in response, campaing design or test email.
What I doing wrong? Or maybe there is another way to solve my problem?
I also tried to ask Mailchimp support about this problem, but got no answer.
The truth is that this feature was not implemented and will not work.
When posting a custom story via the Graph API, is it possible to specify/change the caption of the attachment when I post the story to the user's account, i.e. on the fly?
Right now it defaults to the name of the app posting the action ("Action Center - Scale Review" in the screenshot).
I see in the docs for stories that I can specify up to 4 captions via the UI. But it's not clear to me when these take affect; for example, in the screenshot, I have 4 captions specified for that story - but none are showing. Plus, that's not on the fly/dynamic which is what I'm looking for.
It doesn't look like passing "caption" as an option when posting the action has any effect, nor does a "og:caption" param on the custom object.
I can specify the caption when posting a link via other methods - for example, when publishing a post on a users wall, I can specify the caption for the link.
I am not sure whether those “caption” fields are shown any more for simple objects (the docs might be outdated on this). Even if they are, you can not populate them dynamically, apart from using object property placeholders.
I think you best bet is to use the description (the “Heres a A Demo […]” line in your screenshot) to place the information you want to publish. You can create objects “on the fly” using the Object API. If you want individual objects on a “per user” basis, then this would be the way to go.
To make the captions dynamic you have to add curly braces : example :
by {}
When typed "{" it will show a drop down with your custom objects and you can use your objects to make captions dynamic.
However there is a huge limitation of bringing these captions into new lines.
It's clearly stated in the documentation link you provided.
Here's the code:
$request = new FacebookRequest(
$session,
'POST',
'/me/feed',
array (
'message' => 'This is a test message',
'link' => '',
'picture' => '',
'name' => '',
'caption' => '',
'description' => '',
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
When you click on the arrow next to "link" in the Facebook Docs page, you'll see the other options related to the "link".
I am trying to send a message by the WhatsApp API using PHP. I have the WhatsApp password and am getting by WART using the following code:
<?php
require "whatsapp.class.php";
// DEMO OF USAGE
$wa = new WhatsApp("91XXXXXXXXXX", "XXX-XXX", "Nick Name");
$wa->Connect();
$t = $wa->Login();
$wa->Message("5","91XXXXXXXXXX","Good code");
echo "Message sent";
?>
I did not change anything in the whatsapp.class.php file.
My files are:
http://vvsindia.com/stackoverflow/whatsapp.class.txt
http://vvsindia.com/stackoverflow/func.txt
http://vvsindia.com/stackoverflow/decode.txt
For your convenience to view while browsing, I just uploaded them as a txt file, but originally these are PHP files.
Using the above code I was not able to send any message. What could the issue be?
You can use the below script to send a message from WhatsApp in PHP.
https://github.com/venomous0x/WhatsAPI/tree/master/examples
Configure the source code in Apache and run examples/whatsapp.php file.
You have to change the below configurations.
// Simple password to view this script
$config['webpassword'] = 'MakeUpPassword';
and
$config['YOURNAME'] = array(
'id' => 'e807f1fcf82d132f9bb018ca6738a19f',
'fromNumber' => '441234567890',
'nick' => "YOURNICKNAME",
'waPassword' => "EsdfsawS+/ffdskjsdhwebdgxbs=",
'email' => 'testemail#gmail.com',
'emailPassword' => 'gmailpassword'
);
You should rather try this quick and easy interface API:
https://www.mashape.com/motp/whatsapp-pusher
As given in the documentation, sending a text message to a WhatsApp user would be a one-step process. Below is a sample cURL call to send a text message to a WhatsApp user.
curl -XPOST 'http://api.dial2verify.com/WHAPP/SEND/<API_KEY>/<Phone_ISD>' \
-d 'Msg=Text to image URL here'
To get the API key, you are required to drop a request to hello#dial2verify.in, and they would provide you a free API key.
Phone_ISD: should be a complete phone number including ISD code (for example, 919922003300).
I have a running workflow which I would like to post fields to via an API call (see below):
$ret = invokeFlowgear(
"https://domain.flowgear.io/salesbooks",
"username",
"password",
30,
array(
'name' => 'Introduction to Data integration with Flowgear',
'isbn' => 'X-XXX-XXXX',
'qis' => 0,
'price' => 250.99,
'author_id' => 3
)
);
Eventually this call should result into the workflow inserting the data onto the table and returning a success message.
What do I need to have this achieved with a workflow via an API?
You need to accept the raw HTTP POST body into the Workflow. To do that, set an appropriate URL ("/salesbooks/") in the workflow detail pane and set the method to POST.
Then drop in a Variable Bar and add the special property FgRequestBody. Optionally also add FgRequestContentType so you can inspect the content type of the message being received.
Create an HTTP POST to that Workflow and you can see what's coming through to the FgRequestBody property (it will show in the Start entry in the activity logs).
If you need to convert between JSON and XML, using JSON Convert.
I am trying to render a SoundCloud HTML5 widget using the PHP API, but every time I run the command I think should return the HTML for the widget, I simply get an Exception:
The requested URL responded with HTTP code 302
I realise this is a redirect. What I don't know is why that's all I ever get, or what to do about it to actually get the widget HTML.
The documentation on the API says that to embed the widget using PHP you should do this:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = $client->get('/oembed', array('url' => $track_url));
// render the html for the player widget
print $embed_info['html'];
I'm running this:
// NB: Fully authorised SoundCloud API instance all working prior to this line
// $this->api refers to an authorised instance of Services_Soundcloud
try {
$widget = array_pop(
json_decode( $this->api->get('oembed', array('url' => $track_url)) )
);
print_r($widget);
} catch (Exception $e)
{
print_r($e->getMessage());
}
where "track_url" is actually the URL I get back when asking SoundCloud for a track object earlier in the app using the same API.
I'm not actually sure this URL is correct in the first place, because the track object I get back gives the 'uri' in the form:
[uri] => https://api.soundcloud.com/tracks/62556508
The documentation examples all have a straight http://soundcloud.com/username/track-permalink URL - but even using a known path to a public track the attempt to run the API oembed method fails... I still get a 302 Exception.
Finally, there are mentions of setting "allow_redirects" to false in the 'get' command, but this has no effect when I add to the parameters used to build the query to the API. I also tried adding additional cURL options, but that too had no effect.
I have definitely enabled API access to the track within SoundCloud.
Kind of banging my head off the wall on this. If anyone has any pointers I'd be very grateful to hear them. Just for clarity's sake, I am able to access all the user data, comments etc. via the API instance I have created, so it appears to be working fine.
Thanks for pointing this out. There was a bug in the documentation that lead you astray. Sorry about that. I've updated the docs to fix the bug. Here's the updated code sample:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
$client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => 1));
// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = json_decode($client->get('oembed', array('url' => $track_url)));
// render the html for the player widget
print $embed_info->html;
Note the differences:
You need to set CURLOPT_FOLLOWLOCATION to 1 as mentioned in the comments above.
You need to wrap the return from $client->get in json_decode
The result is an stdClass object, not an Array and so the html property has to be accessed using the -> operator.
Hope that helps. Feel free to comment in case you're still having problems and I'll amend my answer.