Expand my Community achievements bar.

Join expert-led, customer-led sessions on Adobe Experience Manager Assets on August 20th at our Skill Exchange.
SOLVED

Importing a JSON page in AEM using curl

Avatar

Employee

Hi all,

 

I have exported a page from AEM like this:

curl https://myhost/content/prodprj/us/mypg.-1.json | jq > content.json

 

This gives me the page as JSON. 

Now I have made a small change to this change (just changed some text) and I would like to push this change into AEM again.

 

I tried the following:

 

echo content.json | curl -v -F":operation=import" -F":contentType=json" -F":contentFile=@-" -F":nameHint=testing" https://myhost/content/prodprj/us/mypg

 

But that returns a 409 with the following message:

<td>Status</td>
<td><div id="Status">409</div></td>
</tr>
<tr>
<td>Message</td>
<td><div id="Message">repository state conflicting with request</div></td>
</tr>
<tr>
<td>Location</td>
<td><a href="/content/prodprj/us/mypg" id="Location">/content/prodprj/us/mypg</a></td>
</tr>
<tr>
<td>Parent Location</td>
<td><a href="/content/prodprj/us" id="ParentLocation">/content/prodprj/us</a></td>
</tr>
<tr>
<td>Path</td>
<td><div id="Path">/content/prodprj/us/mypg</div></td>
</tr>
<tr>
<td>Referer</td>
<td><div id="Referer"></div></td>
</tr>
<tr>
<td>ChangeLog</td>
<td><div id="ChangeLog">&lt;pre&gt;&lt;/pre&gt;</div></td>
</tr>
</tbody>
</table>
<p><a href="/content/prodprj/us/mypg">Modified Resource</a></p>
<p><a href="/content/prodprj/us">Parent of Modified Resource</a></p>

Does anyone know how to do this? Just export a page in JSON out of AEM, make a small change and then upload it again?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

The JSON Exporter is a delivery url to read AEM content. It doesn't allow write operation. In your case, its easier to open the page in edit mode and directly edit the page instead of XML ways. 

But still if you want an XML way of editing, use the content.xml. So you ll, package the page, download the package, unzip, edit the content.xml inside package, rezip, and ship the package back into AEM.

 

Refer here for curl commands. Steps ll be 

  1. Manually create package from package manager with path as 
    /content/prodprj/us/mypg
  2.  download the package curl -u admin:admin http://localhost:4502/etc/packages/my_packages/test.zip
  3. unzip 
  4. edit content.xml 
  5. rezip
  6. reinstall the package. 

View solution in original post

5 Replies

Avatar

Employee

Or is it easier to do this with a content.xml file?

Avatar

Correct answer by
Community Advisor

The JSON Exporter is a delivery url to read AEM content. It doesn't allow write operation. In your case, its easier to open the page in edit mode and directly edit the page instead of XML ways. 

But still if you want an XML way of editing, use the content.xml. So you ll, package the page, download the package, unzip, edit the content.xml inside package, rezip, and ship the package back into AEM.

 

Refer here for curl commands. Steps ll be 

  1. Manually create package from package manager with path as 
    /content/prodprj/us/mypg
  2.  download the package curl -u admin:admin http://localhost:4502/etc/packages/my_packages/test.zip
  3. unzip 
  4. edit content.xml 
  5. rezip
  6. reinstall the package. 

Avatar

Community Advisor

Hi @bosschaert 

 

You can use the Sling Post Servlet or the content importer service to get the updated json loaded in AEM. Please refer this article - https://blogs.perficient.com/2021/08/16/loading-json-content-into-aem/ for details.

 

Hope this helps!

 

Thanks

Narendra

Avatar

Community Advisor

Hi @bosschaert 

You must be pushing the non-editable properties to AEM since those are imported as part of json. Can you try removing the other properties and just push the content property?

Arun Patidar

AEM LinksLinkedIn

Avatar

Administrator

@bosschaert Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!



Kautuk Sahni